-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: refactor for better edge cases
- Loading branch information
Showing
11 changed files
with
274 additions
and
194 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,42 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Cases\DI; | ||
|
||
use Contributte\Tester\Toolkit; | ||
use Contributte\Tester\Utils\ContainerBuilder; | ||
use Contributte\Tester\Utils\Neonkit; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\ServiceCreationException; | ||
use Nettrine\DBAL\DI\DbalExtension; | ||
use Tester\Assert; | ||
use Tests\Toolkit\Tests; | ||
use Tracy\Bridges\Nette\TracyExtension; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
// Exception (no cache extension) | ||
Toolkit::test(function (): void { | ||
Assert::exception( | ||
function (): void { | ||
ContainerBuilder::of() | ||
->withCompiler(static function (Compiler $compiler): void { | ||
$compiler->addExtension('nettrine.dbal', new DbalExtension()); | ||
$compiler->addExtension('nette.tracy', new TracyExtension()); | ||
$compiler->addConfig([ | ||
'parameters' => [ | ||
'tempDir' => Tests::TEMP_PATH, | ||
'appDir' => Tests::APP_PATH, | ||
], | ||
]); | ||
$compiler->addConfig(Neonkit::load(<<<'NEON' | ||
nettrine.dbal: | ||
connection: | ||
driver: pdo_sqlite | ||
NEON | ||
)); | ||
})->build(); | ||
}, | ||
ServiceCreationException::class, | ||
"~^Service 'nettrine\\.dbal\\.configuration' \\(type of Doctrine\\\\DBAL\\\\Configuration\\): Service of type '?Doctrine\\\\Common\\\\Cache\\\\Cache'? not found\.~" | ||
); | ||
}); |
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,48 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Cases\E2E; | ||
|
||
use Contributte\Tester\Toolkit; | ||
use Contributte\Tester\Utils\ContainerBuilder; | ||
use Contributte\Tester\Utils\Liberator; | ||
use Contributte\Tester\Utils\Neonkit; | ||
use Nette\DI\Compiler; | ||
use Nettrine\Cache\DI\CacheExtension; | ||
use Nettrine\DBAL\DI\DbalExtension; | ||
use Tester\Assert; | ||
use Tests\Toolkit\Tests; | ||
use Tracy\Bridges\Nette\TracyExtension; | ||
use Tracy\Debugger; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
// Debug mode | ||
Toolkit::test(function (): void { | ||
$container = ContainerBuilder::of() | ||
->withCompiler(static function (Compiler $compiler): void { | ||
$compiler->addExtension('nettrine.dbal', new DbalExtension()); | ||
$compiler->addExtension('nettrine.cache', new CacheExtension()); | ||
$compiler->addExtension('nette.tracy', new TracyExtension()); | ||
$compiler->addConfig([ | ||
'parameters' => [ | ||
'tempDir' => Tests::TEMP_PATH, | ||
'appDir' => Tests::APP_PATH, | ||
], | ||
]); | ||
$compiler->addConfig(Neonkit::load(<<<'NEON' | ||
nettrine.dbal: | ||
connection: | ||
driver: pdo_sqlite | ||
debug: | ||
panel: true | ||
NEON | ||
)); | ||
})->build(); | ||
|
||
call_user_func([$container, 'initialize']); | ||
|
||
$blueScreen = Debugger::getBlueScreen(); | ||
$panels = Liberator::of($blueScreen)->panels; | ||
|
||
Assert::count(1, $panels); | ||
}); |
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,22 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Cases\DI; | ||
|
||
use Contributte\Tester\Toolkit; | ||
use Contributte\Tester\Utils\ContainerBuilder; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\InvalidConfigurationException; | ||
use Nettrine\DBAL\DI\DbalExtension; | ||
use Tester\Assert; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
// Exception (no driver) | ||
Toolkit::test(function (): void { | ||
Assert::exception(function (): void { | ||
ContainerBuilder::of() | ||
->withCompiler(static function (Compiler $compiler): void { | ||
$compiler->addExtension('nettrine.dbal', new DbalExtension()); | ||
})->build(); | ||
}, InvalidConfigurationException::class, "The mandatory item 'nettrine.dbal › connection › driver' is missing."); | ||
}); |
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
This file was deleted.
Oops, something went wrong.
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 Tests\Cases\DI; | ||
|
||
use Contributte\Tester\Toolkit; | ||
use Contributte\Tester\Utils\ContainerBuilder; | ||
use Contributte\Tester\Utils\Neonkit; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Platforms\PostgreSQL100Platform; | ||
use Nette\DI\Compiler; | ||
use Nettrine\Cache\DI\CacheExtension; | ||
use Nettrine\DBAL\DI\DbalExtension; | ||
use Tester\Assert; | ||
use Tests\Toolkit\Tests; | ||
use Tracy\Bridges\Nette\TracyExtension; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
// Server version | ||
Toolkit::test(function (): void { | ||
$container = ContainerBuilder::of() | ||
->withCompiler(static function (Compiler $compiler): void { | ||
$compiler->addExtension('nettrine.dbal', new DbalExtension()); | ||
$compiler->addExtension('nettrine.cache', new CacheExtension()); | ||
$compiler->addExtension('nette.tracy', new TracyExtension()); | ||
$compiler->addConfig([ | ||
'parameters' => [ | ||
'tempDir' => Tests::TEMP_PATH, | ||
'appDir' => Tests::APP_PATH, | ||
], | ||
]); | ||
$compiler->addConfig(Neonkit::load(<<<'NEON' | ||
nettrine.dbal: | ||
connection: | ||
driver: pdo_pgsql | ||
serverVersion: 10.0 | ||
NEON | ||
)); | ||
})->build(); | ||
|
||
/** @var Connection $connection */ | ||
$connection = $container->getByType(Connection::class); | ||
|
||
Assert::type(PostgreSQL100Platform::class, $connection->getDatabasePlatform()); | ||
Assert::falsey($connection->isConnected()); | ||
}); |
Oops, something went wrong.