|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Lookyman\Nette\Proxy\Tests; |
|
5
|
|
|
|
|
6
|
|
|
use Lookyman\Nette\Proxy\Tests\Mock\IService2Factory; |
|
7
|
|
|
use Lookyman\Nette\Proxy\Tests\Mock\Service1; |
|
8
|
|
|
use Lookyman\Nette\Proxy\Tests\Mock\Service2; |
|
9
|
|
|
use Nette\Configurator; |
|
10
|
|
|
use ProxyManager\Proxy\ProxyInterface; |
|
11
|
|
|
|
|
12
|
|
|
class ProxyExtensionTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testExtension() |
|
15
|
|
|
{ |
|
16
|
|
|
$tempDir = __DIR__ . '/../temp'; |
|
17
|
|
|
if (!@mkdir($tempDir, 0777, true) && !is_dir($tempDir)) { |
|
18
|
|
|
throw new \RuntimeException(sprintf('Cannot create temp directory %s', $tempDir)); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** @var \SplFileInfo $entry */ |
|
22
|
|
|
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tempDir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $entry) { |
|
23
|
|
|
$entry->isDir() ? rmdir((string) $entry) : unlink((string) $entry); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$container = (new Configurator()) |
|
27
|
|
|
->setTempDirectory($tempDir) |
|
28
|
|
|
->setDebugMode(true) |
|
29
|
|
|
->addConfig(__DIR__ . '/config.neon') |
|
30
|
|
|
->createContainer(); |
|
31
|
|
|
$container->initialize(); |
|
32
|
|
|
|
|
33
|
|
|
/** @var Service1 $service1 */ |
|
34
|
|
|
$service1 = $container->getByType(Service1::class); |
|
35
|
|
|
self::assertInstanceOf(ProxyInterface::class, $service1); |
|
36
|
|
|
self::assertEquals('bar', $service1->foo()); |
|
37
|
|
|
|
|
38
|
|
|
/** @var IService2Factory $service2Factory */ |
|
39
|
|
|
$service2Factory = $container->getByType(IService2Factory::class); |
|
40
|
|
|
self::assertInstanceOf(ProxyInterface::class, $service2Factory); |
|
41
|
|
|
self::assertInstanceOf(Service2::class, $service2Factory->create()); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|