|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spiral\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Monolog\Handler\NullHandler; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use Psr\Http\Message\UriInterface; |
|
9
|
|
|
use Psr\Log\LoggerInterface; |
|
10
|
|
|
use Psr\Log\LoggerTrait; |
|
11
|
|
|
use Psr\Log\LogLevel; |
|
12
|
|
|
use Spiral\Core\Traits\SharedTrait; |
|
13
|
|
|
use Spiral\Debug\Snapshot; |
|
14
|
|
|
use Zend\Diactoros\ServerRequest; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @property \Spiral\Core\MemoryInterface $memory |
|
18
|
|
|
* @property \Spiral\Core\ContainerInterface $container |
|
19
|
|
|
* @property \Spiral\Debug\LogsInterface $logs |
|
20
|
|
|
* @property \Spiral\Http\HttpDispatcher $http |
|
21
|
|
|
* @property \Spiral\Console\ConsoleDispatcher $console |
|
22
|
|
|
* @property \Spiral\Console\ConsoleDispatcher $commands |
|
23
|
|
|
* @property \Spiral\Files\FilesInterface $files |
|
24
|
|
|
* @property \Spiral\Tokenizer\TokenizerInterface $tokenizer |
|
25
|
|
|
* @property \Spiral\Tokenizer\ClassesInterface $locator |
|
26
|
|
|
* @property \Spiral\Tokenizer\InvocationsInterface $invocationLocator |
|
27
|
|
|
* @property \Spiral\Views\ViewManager $views |
|
28
|
|
|
* @property \Spiral\Translator\Translator $translator |
|
29
|
|
|
* @property \Spiral\Database\DatabaseManager $dbal |
|
30
|
|
|
* @property \Spiral\ORM\ORM $orm |
|
31
|
|
|
* @property \Spiral\Encrypter\EncrypterInterface $encrypter |
|
32
|
|
|
* @property \Spiral\Database\Entities\Database $db |
|
33
|
|
|
* @property \Spiral\Http\Cookies\CookieQueue $cookies |
|
34
|
|
|
* @property \Spiral\Http\Routing\RouterInterface $router |
|
35
|
|
|
* @property \Spiral\Pagination\PaginatorsInterface $paginators |
|
36
|
|
|
* @property \Psr\Http\Message\ServerRequestInterface $request |
|
37
|
|
|
* @property \Spiral\Http\Request\InputManager $input |
|
38
|
|
|
* @property \Spiral\Http\Response\ResponseWrapper $response |
|
39
|
|
|
* @property \Spiral\Http\Routing\RouteInterface $route |
|
40
|
|
|
* @property \Spiral\Security\PermissionsInterface $permissions |
|
41
|
|
|
* @property \Spiral\Security\RulesInterface $rules |
|
42
|
|
|
* @property \Spiral\Security\ActorInterface $actor |
|
43
|
|
|
* @property \Spiral\Session\SessionInterface $session |
|
44
|
|
|
*/ |
|
45
|
|
|
abstract class BaseTest extends TestCase |
|
46
|
|
|
{ |
|
47
|
|
|
use SharedTrait; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var TestApplication |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $app; |
|
53
|
|
|
|
|
54
|
|
|
public function setUp() |
|
55
|
|
|
{ |
|
56
|
|
|
$root = __DIR__ . '/-app-/'; |
|
57
|
|
|
$this->app = TestApplication::init( |
|
|
|
|
|
|
58
|
|
|
[ |
|
59
|
|
|
'root' => $root, |
|
60
|
|
|
'libraries' => dirname(__DIR__) . '/vendor/', |
|
61
|
|
|
'application' => $root, |
|
62
|
|
|
'framework' => dirname(__DIR__) . '/source/', |
|
63
|
|
|
'runtime' => $root . 'runtime/', |
|
64
|
|
|
'cache' => $root . 'runtime/cache/', |
|
65
|
|
|
], |
|
66
|
|
|
null, |
|
67
|
|
|
null, |
|
68
|
|
|
false |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
//Monolog love to write to CLI when no handler set |
|
72
|
|
|
$this->app->logs->debugHandler(new NullHandler()); |
|
73
|
|
|
$this->app->container->bind('factory', $this->app->container); |
|
74
|
|
|
|
|
75
|
|
|
$files = $this->app->files; |
|
76
|
|
|
|
|
77
|
|
|
//Ensure runtime is clean |
|
78
|
|
|
foreach ($files->getFiles($this->app->directory('runtime')) as $filename) { |
|
79
|
|
|
//If exception is thrown here this will mean that application wasn't correctly |
|
80
|
|
|
//destructed and there is open resources kept |
|
81
|
|
|
$files->delete($filename); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
clearstatcache(); |
|
85
|
|
|
|
|
86
|
|
|
//Open application scope |
|
87
|
|
|
TestApplication::shareContainer($this->app->container); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* This method performs full destroy of spiral environment. |
|
92
|
|
|
*/ |
|
93
|
|
|
public function tearDown() |
|
94
|
|
|
{ |
|
95
|
|
|
\Mockery::close(); |
|
96
|
|
|
|
|
97
|
|
|
TestApplication::shareContainer(null); |
|
98
|
|
|
|
|
99
|
|
|
//Forcing destruction |
|
100
|
|
|
$this->app = null; |
|
101
|
|
|
|
|
102
|
|
|
gc_collect_cycles(); |
|
103
|
|
|
clearstatcache(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return \Spiral\Core\ContainerInterface |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function iocContainer() |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->app->container; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param string $message |
|
117
|
|
|
* @param int $code |
|
118
|
|
|
* @return Snapshot |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function makeSnapshot(string $message, int $code): Snapshot |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->factory->make(Snapshot::class, [ |
|
|
|
|
|
|
123
|
|
|
'exception' => new \Error($message, $code) |
|
|
|
|
|
|
124
|
|
|
]); |
|
125
|
|
|
} |
|
126
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..