Init
This commit is contained in:
56
tests/cases/Integration/Container/ContainerBuild.phpt
Normal file
56
tests/cases/Integration/Container/ContainerBuild.phpt
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Tests\Integration\Container;
|
||||
|
||||
use Nette\Configurator;
|
||||
use Nette\DI\Container;
|
||||
use Tester\Assert;
|
||||
use Throwable;
|
||||
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
|
||||
$rootDir = realpath(__DIR__ . '/../../../..');
|
||||
$parameters = [
|
||||
'rootDir' => $rootDir,
|
||||
'appDir' => $rootDir . '/app',
|
||||
'wwwDir' => $rootDir . '/www',
|
||||
'database' => [
|
||||
'host' => 'fake',
|
||||
'user' => 'fake',
|
||||
'password' => 'fake',
|
||||
'dbname' => 'fake',
|
||||
],
|
||||
];
|
||||
|
||||
// Production container build
|
||||
test(function () use ($parameters): void {
|
||||
$configurator = new Configurator();
|
||||
$configurator->setTempDirectory(TEMP_DIR);
|
||||
|
||||
$configurator->addConfig($parameters['rootDir'] . '/config/env/prod.neon');
|
||||
$configurator->addParameters($parameters);
|
||||
|
||||
try {
|
||||
$configurator->setDebugMode(false);
|
||||
$container = $configurator->createContainer();
|
||||
Assert::type(Container::class, $container);
|
||||
} catch (Throwable $t) {
|
||||
Assert::fail(sprintf('Building production container failed. Exception: %s.', $t->getMessage()));
|
||||
}
|
||||
});
|
||||
|
||||
// Development container build
|
||||
test(function () use ($parameters): void {
|
||||
$configurator = new Configurator();
|
||||
$configurator->setTempDirectory(TEMP_DIR);
|
||||
|
||||
$configurator->addConfig($parameters['rootDir'] . '/config/env/dev.neon');
|
||||
$configurator->addParameters($parameters);
|
||||
try {
|
||||
$configurator->setDebugMode(false);
|
||||
$container = $configurator->createContainer();
|
||||
Assert::type(Container::class, $container);
|
||||
} catch (Throwable $t) {
|
||||
Assert::fail(sprintf('Building development container failed. Exception: %s.', $t->getMessage()));
|
||||
}
|
||||
});
|
||||
27
tests/cases/Integration/Database/Entity/MappingTest.phpt
Normal file
27
tests/cases/Integration/Database/Entity/MappingTest.phpt
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Tests\Integration\Database\Entity;
|
||||
|
||||
use App\Model\Database\EntityManager;
|
||||
use Doctrine\ORM\Tools\SchemaValidator;
|
||||
use Nette\DI\Container;
|
||||
use Tester\Assert;
|
||||
|
||||
/** @var Container $container */
|
||||
$container = require_once __DIR__ . '/../../../../bootstrap.container.php';
|
||||
|
||||
test(function () use ($container): void {
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->getByType(EntityManager::class);
|
||||
|
||||
// Validation
|
||||
$validator = new SchemaValidator($em);
|
||||
$validations = $validator->validateMapping();
|
||||
foreach ($validations as $fails) {
|
||||
foreach ((array) $fails as $fail) {
|
||||
Assert::fail($fail);
|
||||
}
|
||||
}
|
||||
|
||||
Assert::count(0, $validations);
|
||||
});
|
||||
31
tests/cases/Integration/Database/TRepositoriesTest.php
Normal file
31
tests/cases/Integration/Database/TRepositoriesTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Tests\Integration\Database;
|
||||
|
||||
use App\Model\Database\EntityManager;
|
||||
use App\Model\Database\TRepositories;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Nette\DI\Container;
|
||||
use ReflectionClass;
|
||||
use Tester\Assert;
|
||||
|
||||
/** @var Container $container */
|
||||
$container = require_once __DIR__ . '/../../../bootstrap.container.php';
|
||||
|
||||
test(function () use ($container): void {
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->getByType(EntityManager::class);
|
||||
|
||||
/** @var ClassMetadata[] $metadata */
|
||||
$metadata = $em->getMetadataFactory()->getAllMetadata();
|
||||
|
||||
foreach ($metadata as $item) {
|
||||
$entityClass = $item->getName();
|
||||
$methodName = 'get' . (new ReflectionClass($entityClass))->getShortName() . 'Repository';
|
||||
Assert::true(
|
||||
method_exists($em, $methodName),
|
||||
sprintf('Method %s() not exist in %s or %s', $methodName, TRepositories::class, EntityManager::class)
|
||||
);
|
||||
Assert::same($em->getRepository($entityClass), $em->$methodName());
|
||||
}
|
||||
});
|
||||
34
tests/cases/Integration/Latte/CompilerTest.phpt
Normal file
34
tests/cases/Integration/Latte/CompilerTest.phpt
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Tests\Integration\Latte;
|
||||
|
||||
use App\Model\Latte\TemplateFactory;
|
||||
use Nette\Application\UI\ITemplateFactory;
|
||||
use Nette\Bridges\ApplicationLatte\Template;
|
||||
use Nette\DI\Container;
|
||||
use Nette\Utils\Finder;
|
||||
use SplFileInfo;
|
||||
use Tester\Assert;
|
||||
use Throwable;
|
||||
|
||||
/** @var Container $container */
|
||||
$container = require_once __DIR__ . '/../../../bootstrap.container.php';
|
||||
|
||||
test(function () use ($container): void {
|
||||
/** @var ITemplateFactory $templateFactory */
|
||||
$templateFactory = $container->getByType(ITemplateFactory::class);
|
||||
Assert::type(TemplateFactory::class, $templateFactory);
|
||||
|
||||
/** @var Template $template */
|
||||
$template = $templateFactory->createTemplate();
|
||||
$finder = Finder::findFiles('*.latte')->from(APP_DIR);
|
||||
|
||||
try {
|
||||
/** @var SplFileInfo $file */
|
||||
foreach ($finder as $file) {
|
||||
$template->getLatte()->warmupCache($file->getRealPath());
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
Assert::fail(sprintf('Template compilation failed ([%s] %s)', get_class($e), $e->getMessage()));
|
||||
}
|
||||
});
|
||||
16
tests/cases/Unit/Model/Utils/Strings.phpt
Normal file
16
tests/cases/Unit/Model/Utils/Strings.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
use App\Model\Utils\Strings;
|
||||
use Tester\Assert;
|
||||
|
||||
require_once __DIR__ . '/../../../../bootstrap.php';
|
||||
|
||||
// Strings::slashless
|
||||
test(function (): void {
|
||||
$input = 'foo//bar/////test/asd';
|
||||
$expected = 'foo/bar/test/asd';
|
||||
|
||||
$result = Strings::slashless($input);
|
||||
|
||||
Assert::same($expected, $result);
|
||||
});
|
||||
Reference in New Issue
Block a user