|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AbterPhp\Framework\Bootstrappers\Http; |
|
4
|
|
|
|
|
5
|
|
|
use AbterPhp\Framework\Constant\Env; |
|
6
|
|
|
use AbterPhp\Framework\Environments\Environment; |
|
7
|
|
|
use AbterPhp\Framework\I18n\ITranslator; |
|
8
|
|
|
use AbterPhp\Framework\Module\Manager; |
|
9
|
|
|
use Opulence\Framework\Configuration\Config; |
|
10
|
|
|
use Opulence\Ioc\Container; |
|
11
|
|
|
use Opulence\Views\Caching\ArrayCache; |
|
12
|
|
|
use Opulence\Views\Caching\ICache; |
|
13
|
|
|
use Opulence\Views\Compilers\Fortune\ITranspiler; |
|
14
|
|
|
use Opulence\Views\Compilers\ICompiler; |
|
15
|
|
|
use Opulence\Views\Factories\IO\IViewReader; |
|
16
|
|
|
use Opulence\Views\Factories\IViewFactory; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
class ViewBootstrapperTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var ViewBootstrapper */ |
|
22
|
|
|
protected ViewBootstrapper $sut; |
|
23
|
|
|
|
|
24
|
|
|
protected Manager $moduleManagerMock; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp(): void |
|
27
|
|
|
{ |
|
28
|
|
|
global $abterModuleManager; |
|
29
|
|
|
|
|
30
|
|
|
$this->sut = new ViewBootstrapper(); |
|
31
|
|
|
|
|
32
|
|
|
$this->moduleManagerMock = $this->getMockBuilder(Manager::class)->disableOriginalConstructor()->getMock(); |
|
33
|
|
|
|
|
34
|
|
|
$abterModuleManager = $this->moduleManagerMock; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function tearDown(): void |
|
38
|
|
|
{ |
|
39
|
|
|
global $abterModuleManager; |
|
40
|
|
|
|
|
41
|
|
|
Environment::unsetVar(Env::ENV_NAME); |
|
42
|
|
|
|
|
43
|
|
|
$abterModuleManager = null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testRegisterBindings() |
|
47
|
|
|
{ |
|
48
|
|
|
Environment::setVar(Env::ENV_NAME, 'foo'); |
|
49
|
|
|
|
|
50
|
|
|
$invalidViewRoot = '/tmp/foo' . rand(100, 999); |
|
51
|
|
|
$validViewRoot = '/tmp/foo' . rand(10, 99); |
|
52
|
|
|
|
|
53
|
|
|
Config::set('views', 'cache', ArrayCache::class); |
|
54
|
|
|
Config::set('paths', 'views.raw', $invalidViewRoot); |
|
55
|
|
|
|
|
56
|
|
|
mkdir("$validViewRoot/views", 0777, true); |
|
57
|
|
|
|
|
58
|
|
|
$resourcePaths = [$invalidViewRoot, $validViewRoot]; |
|
59
|
|
|
|
|
60
|
|
|
$this->moduleManagerMock->expects($this->once())->method('getResourcePaths')->willReturn($resourcePaths); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$mockTranslator = $this->getMockBuilder(ITranslator::class)->getMock(); |
|
63
|
|
|
|
|
64
|
|
|
$container = new Container(); |
|
65
|
|
|
$container->bindInstance(ITranslator::class, $mockTranslator); |
|
66
|
|
|
|
|
67
|
|
|
$this->sut->registerBindings($container); |
|
68
|
|
|
|
|
69
|
|
|
$actual = $container->resolve(ICache::class); |
|
70
|
|
|
$this->assertInstanceOf(ICache::class, $actual); |
|
71
|
|
|
|
|
72
|
|
|
$actual = $container->resolve(ICompiler::class); |
|
73
|
|
|
$this->assertInstanceOf(ICompiler::class, $actual); |
|
74
|
|
|
|
|
75
|
|
|
$actual = $container->resolve(ITranspiler::class); |
|
76
|
|
|
$this->assertInstanceOf(ITranspiler::class, $actual); |
|
77
|
|
|
|
|
78
|
|
|
$actual = $container->resolve(IViewFactory::class); |
|
79
|
|
|
$this->assertInstanceOf(IViewFactory::class, $actual); |
|
80
|
|
|
|
|
81
|
|
|
$actual = $container->resolve(IViewReader::class); |
|
82
|
|
|
$this->assertInstanceOf(IViewReader::class, $actual); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.