• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zfegg / expressive-test / 9520702861

14 Jun 2024 06:26PM UTC coverage: 95.913%. Remained the same
9520702861

Pull #17

github

web-flow
Merge 8ff6b65e4 into 7012ec157
Pull Request #17: Update deps

352 of 367 relevant lines covered (95.91%)

4.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/src/Helper/SetupApplicationTrait.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Zfegg\ExpressiveTest\Helper;
6

7
use Composer\Autoload\ClassLoader;
8
use Laminas\Stratigility\Middleware\ErrorHandler;
9
use Mezzio\Application;
10
use Mezzio\MiddlewareFactory;
11
use Psr\Container\ContainerInterface;
12
use Psr\Http\Message\ResponseInterface;
13
use ReflectionClass;
14
use Zfegg\ExpressiveTest\MockRequestFactory;
15
use Zfegg\ExpressiveTest\PassMiddleware;
16

17
trait SetupApplicationTrait
18
{
19
    /**
20
     * @var ContainerInterface|\Laminas\ServiceManager\ServiceManager
21
     */
22
    protected $container;
23

24
    protected function getProjectDir(): string
25
    {
26
        $reflector = new ReflectionClass(ClassLoader::class);
20✔
27
        $file      = $reflector->getFileName();
20✔
28
        return realpath(dirname($file) . '/../../');
20✔
29
    }
30

31
    public function loadContainer(): ContainerInterface
32
    {
33
        if ($this->container) {
20✔
34
            return $this->container;
1✔
35
        }
36

37
        $projectRoot = $this->getProjectDir();
20✔
38

39
        $containerFile = $projectRoot . '/config/container.php';
20✔
40
        if (file_exists($containerFile)) {
20✔
41
            $this->container = include $containerFile;
20✔
42

43
            return $this->container;
20✔
44
        }
45

46
        throw new \RuntimeException('Load container error.');
×
47
    }
48

49
    protected function setUp(): void
50
    {
51
        chdir($this->getProjectDir());
20✔
52
        $this->container = $this->loadContainer();
20✔
53
        $this->container->setAllowOverride(true);
20✔
54
        $this->container->setService(ErrorHandler::class, new PassMiddleware());
20✔
55
        $this->container->addDelegator(
20✔
56
            Application::class,
20✔
57
            function ($container, $name, callable $callback) {
20✔
58
                $app         = $callback();
14✔
59
                $factory     = $container->get(MiddlewareFactory::class);
14✔
60
                $projectRoot = $this->getProjectDir();
14✔
61

62
                foreach (['pipeline', 'routes'] as $file) {
14✔
63
                    $file = $projectRoot . "/config/$file.php";
14✔
64
                    if (file_exists($file)) {
14✔
65
                        (require $file)($app, $factory, $container);
14✔
66
                    }
67
                }
68

69
                return $app;
14✔
70
            }
20✔
71
        );
20✔
72
    }
73

74
    public function runApp(
75
        string $method,
76
        string $requestUri,
77
        array $parsedBody = [],
78
        array $servers = [],
79
        $body = null,
80
        array $cookies = [],
81
        array $files = []
82
    ): ResponseInterface {
83

84
        $servers['REQUEST_METHOD'] = $method;
14✔
85
        $servers['REQUEST_URI']    = $requestUri;
14✔
86

87
        $request = MockRequestFactory::create($servers, $parsedBody, $body, $cookies, $files);
14✔
88

89
        /** @var \Mezzio\Application $app */
90
        $app = $this->container->get(Application::class);
13✔
91

92
        return $app->handle($request);
13✔
93
    }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc