-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 168447a
Showing
23 changed files
with
1,443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/composer.lock | ||
/tests/temp | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "mangoweb/presenter-tester", | ||
"license": "MIT", | ||
"require": { | ||
"php": "~7.1", | ||
"nette/di": "~2.4", | ||
"nette/bootstrap": "~2.4", | ||
"nette/tester": "~2.0" | ||
}, | ||
"require-dev": { | ||
"nette/utils": "~2.4", | ||
"nette/http": "~2.4", | ||
"nette/reflection": "^2.4" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"src" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mangoweb\Tester\Infrastructure\Bridges\Database; | ||
|
||
use Mangoweb\Tester\DatabaseCreator\DatabaseCreator; | ||
use Mangoweb\Tester\Infrastructure\Container\IAppContainerHook; | ||
use Nette\Configurator; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerBuilder; | ||
|
||
|
||
class DatabaseCreatorHook implements IAppContainerHook | ||
{ | ||
|
||
/** @var DatabaseCreator */ | ||
private $databaseCreator; | ||
|
||
|
||
public function __construct(DatabaseCreator $databaseCreator) | ||
{ | ||
$this->databaseCreator = $databaseCreator; | ||
} | ||
|
||
|
||
public function onConfigure(Configurator $configurator): void | ||
{ | ||
|
||
} | ||
|
||
|
||
public function onCompile(ContainerBuilder $builder): void | ||
{ | ||
$builder->addDefinition('databaseCreator') | ||
->setClass(DatabaseCreator::class) | ||
->setDynamic() | ||
->setAutowired(FALSE); | ||
$builder->prepareClassList(); | ||
} | ||
|
||
|
||
public function onCreate(Container $applicationContainer): void | ||
{ | ||
$applicationContainer->addService('databaseCreator', $this->databaseCreator); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mangoweb\Tester\Infrastructure\Bridges\MailTester; | ||
|
||
use Mangoweb\MailTester\TestMailer; | ||
use Mangoweb\Tester\Infrastructure\Container\IAppContainerHook; | ||
use Nette\Configurator; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerBuilder; | ||
|
||
|
||
class MailTesterContainerHook implements IAppContainerHook | ||
{ | ||
|
||
public function onConfigure(Configurator $configurator): void | ||
{ | ||
|
||
} | ||
|
||
|
||
public function onCompile(ContainerBuilder $builder): void | ||
{ | ||
$builder->getDefinition('mail.mailer') | ||
->setClass(TestMailer::class) | ||
->setFactory(TestMailer::class); | ||
} | ||
|
||
|
||
public function onCreate(Container $applicationContainer): void | ||
{ | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mangoweb\Tester\Infrastructure\Bridges\MailTester; | ||
|
||
use Mangoweb\MailTester\MailTester; | ||
use Mangoweb\Tester\Infrastructure\ITestCaseListener; | ||
use Mangoweb\Tester\Infrastructure\TestCase; | ||
|
||
|
||
class MailTesterTestCaseListener implements ITestCaseListener | ||
{ | ||
|
||
/** @var MailTester */ | ||
private $mailTester; | ||
|
||
|
||
public function __construct(MailTester $mailTester) | ||
{ | ||
$this->mailTester = $mailTester; | ||
} | ||
|
||
|
||
public function setUp(TestCase $testCase): void | ||
{ | ||
} | ||
|
||
|
||
public function tearDown(TestCase $testCase): void | ||
{ | ||
$this->mailTester->assertNone(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mangoweb\Tester\Infrastructure\Bridges\Mockery; | ||
|
||
use Mangoweb\Tester\Infrastructure\Container\IAppContainerHook; | ||
use Mangoweb\Tester\Infrastructure\TestContext; | ||
use Mockery\MockInterface; | ||
use Nette\Configurator; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerBuilder; | ||
use Nette\Reflection\AnnotationsParser; | ||
use Nette\Utils\Strings; | ||
|
||
class MockeryContainerHook implements IAppContainerHook | ||
{ | ||
|
||
/** @var TestContext */ | ||
private $testContext; | ||
|
||
|
||
public function __construct(TestContext $testContext) | ||
{ | ||
$this->testContext = $testContext; | ||
} | ||
|
||
|
||
public function onConfigure(Configurator $configurator): void | ||
{ | ||
|
||
} | ||
|
||
|
||
public function onCompile(ContainerBuilder $builder): void | ||
{ | ||
} | ||
|
||
|
||
public function onCreate(Container $applicationContainer): void | ||
{ | ||
$rc = new \ReflectionClass($this->testContext->getTestCaseClass()); | ||
$rm = $rc->getMethod($this->testContext->getTestMethod()); | ||
$doc = $rm->getDocComment(); | ||
$params = Strings::matchAll($doc, '~\*\s+@param\s+([\w_\\\\|]+)\s+(\$[\w_]+)(?:\s+.*)?$~m'); | ||
foreach ($params as [, $types, $paramName]) { | ||
$types = explode('|', $types); | ||
if (count($types) !== 2) { | ||
continue; | ||
} | ||
[$requiredType, $mockeryType] = $types; | ||
$requiredType = AnnotationsParser::expandClassName($requiredType, $rc); | ||
$mockeryType = AnnotationsParser::expandClassName($mockeryType, $rc); | ||
if ($mockeryType !== MockInterface::class) { | ||
continue; | ||
} | ||
$applicationContainer->addService($applicationContainer->findByType($requiredType)[0], \Mockery::mock($requiredType)); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mangoweb\Tester\Infrastructure\Bridges\NextrasDbal; | ||
|
||
use Mangoweb\Tester\Infrastructure\Container\IAppContainerHook; | ||
use Nette\Configurator; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerBuilder; | ||
use Nette\DI\Statement; | ||
use Nextras\Dbal\Connection; | ||
|
||
|
||
class NextrasDbalHook implements IAppContainerHook | ||
{ | ||
|
||
public function onConfigure(Configurator $configurator): void | ||
{ | ||
|
||
} | ||
|
||
|
||
public function onCompile(ContainerBuilder $builder): void | ||
{ | ||
$def = $builder->getDefinitionByType(Connection::class); | ||
$factory = $def->getFactory(); | ||
assert($factory !== NULL); | ||
$args = $factory->arguments; | ||
$args['config'] = new Statement('array_merge(?, ?)', [ | ||
$args['config'], | ||
[ | ||
'database' => new Statement('@databaseCreator::getDatabaseName'), | ||
], | ||
]); | ||
$def->setArguments($args); | ||
$def->addSetup(['@databaseCreator', 'createTestDatabase']); | ||
} | ||
|
||
|
||
public function onCreate(Container $applicationContainer): void | ||
{ | ||
|
||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/Bridges/PresenterTester/PresenterTesterTestCaseListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mangoweb\Tester\Infrastructure\Bridges\PresenterTester; | ||
|
||
use Mangoweb\Tester\Infrastructure\ITestCaseListener; | ||
use Mangoweb\Tester\Infrastructure\TestCase; | ||
use Mangoweb\Tester\PresenterTester\PresenterTester; | ||
use Tester\Assert; | ||
|
||
|
||
class PresenterTesterTestCaseListener implements ITestCaseListener | ||
{ | ||
|
||
/** @var PresenterTester|NULL */ | ||
public $presenterTester; | ||
|
||
|
||
public function setUp(TestCase $testCase): void | ||
{ | ||
} | ||
|
||
|
||
public function tearDown(TestCase $testCase): void | ||
{ | ||
if (!$this->presenterTester) { | ||
return; | ||
} | ||
foreach ($this->presenterTester->getResults() as $i => $result) { | ||
if (!$result->wasResponseInspected()) { | ||
Assert::fail(sprintf('Request #%d to %s presenter was not asserted', $i + 1, $result->getRequest()->getPresenterName())); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mangoweb\Tester\Infrastructure\Container; | ||
|
||
use Mangoweb\Tester\Infrastructure\MangoTesterExtension; | ||
use Nette\Configurator; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerBuilder; | ||
|
||
|
||
class AppContainerFactory | ||
{ | ||
|
||
/** @var IAppConfiguratorFactory */ | ||
private $appConfiguratorFactory; | ||
|
||
|
||
public function __construct(IAppConfiguratorFactory $appConfiguratorFactory) | ||
{ | ||
$this->appConfiguratorFactory = $appConfiguratorFactory; | ||
} | ||
|
||
|
||
public function create(Container $testContainer, ?IAppContainerHook $testCaseHook): Container | ||
{ | ||
$configurator = $this->appConfiguratorFactory->create($testContainer); | ||
|
||
$hook = $this->getHook($testContainer); | ||
if ($testCaseHook) { | ||
$hook = new AppContainerHookList([$hook, $testCaseHook]); | ||
} | ||
$this->setupConfigurator($testContainer, $configurator, $hook); | ||
|
||
$appContainer = $configurator->createContainer(); | ||
$hook->onCreate($appContainer); | ||
assert($appContainer instanceof Container); | ||
|
||
return $appContainer; | ||
} | ||
|
||
|
||
protected function setupConfigurator(Container $testContainer, Configurator $configurator, IAppContainerHook $hook): void | ||
{ | ||
$configurator->addParameters([ | ||
'hooksHash' => md5(serialize(get_class($hook))), | ||
]); | ||
$hook->onConfigure($configurator); | ||
$configurator->onCompile[] = function ($configurator, Compiler $compiler) use ($hook) { | ||
$compilerExtension = new CompilerHookExtension(); | ||
$compilerExtension->onBeforeCompile[] = function (ContainerBuilder $builder) use ($hook) { | ||
$hook->onCompile($builder); | ||
}; | ||
$compiler->addExtension('tests.beforeCompile', $compilerExtension); | ||
}; | ||
|
||
$configurator->addParameters([ | ||
'testContainerParameters' => $testContainer->getParameters(), | ||
]); | ||
} | ||
|
||
|
||
protected function getHook(Container $testContainer): IAppContainerHook | ||
{ | ||
$hooks = []; | ||
foreach ($testContainer->findByTag(MangoTesterExtension::TAG_HOOK) as $hookName => $_) { | ||
$hook = $testContainer->getService($hookName); | ||
assert($hook instanceof IAppContainerHook); | ||
$hooks[] = $hook; | ||
} | ||
return new AppContainerHookList($hooks); | ||
} | ||
|
||
} |
Oops, something went wrong.