Skip to content

Commit 9f7aa17

Browse files
committed
reorder the public methods used by the module
1 parent 1edd1cb commit 9f7aa17

File tree

1 file changed

+114
-70
lines changed

1 file changed

+114
-70
lines changed

src/Codeception/Lib/Connector/Laravel.php

Lines changed: 114 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Codeception\Lib\Connector;
66

7+
use Closure;
78
use Codeception\Lib\Connector\Laravel\ExceptionHandlerDecorator as LaravelExceptionHandlerDecorator;
89
use Codeception\Lib\Connector\Laravel6\ExceptionHandlerDecorator as Laravel6ExceptionHandlerDecorator;
910
use Codeception\Module\Laravel\ServicesTrait;
@@ -261,76 +262,6 @@ private function normalizeEvent($event): string
261262
return $segments[0];
262263
}
263264

264-
//======================================================================
265-
// Public methods called by module
266-
//======================================================================
267-
268-
/**
269-
* Did an event trigger?
270-
*
271-
* @param $event
272-
* @return bool
273-
*/
274-
public function eventTriggered($event): bool
275-
{
276-
$event = $this->normalizeEvent($event);
277-
278-
foreach ($this->triggeredEvents as $triggeredEvent) {
279-
if ($event == $triggeredEvent || is_subclass_of($event, $triggeredEvent)) {
280-
return true;
281-
}
282-
}
283-
284-
return false;
285-
}
286-
287-
/**
288-
* Disable Laravel exception handling.
289-
*/
290-
public function disableExceptionHandling(): void
291-
{
292-
$this->exceptionHandlingDisabled = true;
293-
$this->app[ExceptionHandler::class]->exceptionHandlingDisabled(true);
294-
}
295-
296-
/**
297-
* Enable Laravel exception handling.
298-
*/
299-
public function enableExceptionHandling(): void
300-
{
301-
$this->exceptionHandlingDisabled = false;
302-
$this->app[ExceptionHandler::class]->exceptionHandlingDisabled(false);
303-
}
304-
305-
/**
306-
* Disable events.
307-
*
308-
* @throws Exception
309-
*/
310-
public function disableEvents(): void
311-
{
312-
$this->eventsDisabled = true;
313-
$this->mockEventDispatcher();
314-
}
315-
316-
/**
317-
* Disable model events.
318-
*/
319-
public function disableModelEvents(): void
320-
{
321-
$this->modelEventsDisabled = true;
322-
Model::unsetEventDispatcher();
323-
}
324-
325-
/*
326-
* Disable middleware.
327-
*/
328-
public function disableMiddleware(): void
329-
{
330-
$this->middlewareDisabled = true;
331-
$this->app->instance('middleware.disable', true);
332-
}
333-
334265
/**
335266
* Apply the registered application handlers.
336267
*/
@@ -403,4 +334,117 @@ private function convertToTestFiles(array &$files): array
403334

404335
return $filtered;
405336
}
337+
338+
// Public methods called by module
339+
340+
public function clearApplicationHandlers(): void
341+
{
342+
$this->applicationHandlers = [];
343+
}
344+
345+
public function disableEvents(): void
346+
{
347+
$this->eventsDisabled = true;
348+
$this->mockEventDispatcher();
349+
}
350+
351+
public function disableExceptionHandling(): void
352+
{
353+
$this->exceptionHandlingDisabled = true;
354+
$this->getExceptionHandler()->exceptionHandlingDisabled(true);
355+
}
356+
357+
public function disableMiddleware($middleware = null): void
358+
{
359+
if (is_null($middleware)) {
360+
$this->middlewareDisabled = true;
361+
362+
$this->app->instance('middleware.disable', true);
363+
return;
364+
}
365+
366+
foreach ((array) $middleware as $abstract) {
367+
$this->app->instance($abstract, new class
368+
{
369+
public function handle($request, $next)
370+
{
371+
return $next($request);
372+
}
373+
});
374+
}
375+
}
376+
377+
public function disableModelEvents(): void
378+
{
379+
$this->modelEventsDisabled = true;
380+
Model::unsetEventDispatcher();
381+
}
382+
383+
public function enableExceptionHandling(): void
384+
{
385+
$this->exceptionHandlingDisabled = false;
386+
$this->getExceptionHandler()->exceptionHandlingDisabled(false);
387+
}
388+
389+
public function enableMiddleware($middleware = null): void
390+
{
391+
if (is_null($middleware)) {
392+
$this->middlewareDisabled = false;
393+
394+
unset($this->app['middleware.disable']);
395+
return;
396+
}
397+
398+
foreach ((array) $middleware as $abstract) {
399+
unset($this->app[$abstract]);
400+
}
401+
}
402+
403+
/**
404+
* Did an event trigger?
405+
*
406+
* @param object|string $event
407+
*/
408+
public function eventTriggered($event): bool
409+
{
410+
$event = $this->normalizeEvent($event);
411+
412+
foreach ($this->triggeredEvents as $triggeredEvent) {
413+
if ($event == $triggeredEvent || is_subclass_of($event, $triggeredEvent)) {
414+
return true;
415+
}
416+
}
417+
418+
return false;
419+
}
420+
421+
public function haveApplicationHandler(callable $handler): void
422+
{
423+
$this->applicationHandlers[] = $handler;
424+
}
425+
426+
/**
427+
* @param Closure|string|null $concrete
428+
*/
429+
public function haveBinding(string $abstract, $concrete, bool $shared = false): void
430+
{
431+
$this->bindings[$abstract] = [$concrete, $shared];
432+
}
433+
434+
/**
435+
* @param Closure|string $implementation
436+
*/
437+
public function haveContextualBinding(string $concrete, string $abstract, $implementation): void
438+
{
439+
if (! isset($this->contextualBindings[$concrete])) {
440+
$this->contextualBindings[$concrete] = [];
441+
}
442+
443+
$this->contextualBindings[$concrete][$abstract] = $implementation;
444+
}
445+
446+
public function haveInstance(string $abstract, object $instance): void
447+
{
448+
$this->instances[$abstract] = $instance;
449+
}
406450
}

0 commit comments

Comments
 (0)