Skip to content

Commit

Permalink
Tests: modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jun 10, 2023
1 parent c7b0095 commit 5b9c3fd
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 152 deletions.
109 changes: 109 additions & 0 deletions tests/Cases/Unit/DI/MigrationsExtension.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php declare(strict_types = 1);

namespace Tests\Cases\Unit\DI;

use Contributte\Tester\Toolkit;
use Contributte\Tester\Utils\ContainerBuilder;
use Contributte\Tester\Utils\Neonkit;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand;
use Nette\DI\Compiler;
use Nettrine\Migrations\DI\MigrationsExtension;
use Nettrine\Migrations\Version\DbalMigrationFactory;
use Symfony\Component\Console\Application;
use Tester\Assert;
use Tests\Toolkit\NeonLoader;

require_once __DIR__ . '/../../../bootstrap.php';

Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('migrations', new MigrationsExtension());
$compiler->addConfig(Neonkit::load('
parameters:
appDir: /root
migrations:
directory: %appDir%/migrations
services:
- Symfony\Component\Console\Application
- Doctrine\DBAL\Driver\Mysqli\Driver
- Doctrine\DBAL\Connection([])
'));
$compiler->addDependencies([__FILE__]);
})
->build();

/** @var Configuration $configuration */
$configuration = $container->getByType(Configuration::class);
Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories());
Assert::count(13, $container->findByType(DoctrineCommand::class));
// 4 default helpers
Assert::count(4, iterator_to_array($container->getByType(Application::class)->getHelperSet()));
});

Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('migrations', new MigrationsExtension());
$compiler->addConfig(Neonkit::load('
migrations:
directory: /fake/migrations
namespace: Fake
services:
- Doctrine\DBAL\Driver\Mysqli\Driver
- Doctrine\DBAL\Connection([])
'));
$compiler->addDependencies([__FILE__]);
})
->build();

/** @var Configuration $configuration */
$configuration = $container->getByType(Configuration::class);
Assert::equal(['Fake' => '/fake/migrations'], $configuration->getMigrationDirectories());
});

Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('migrations', new MigrationsExtension());
$compiler->addConfig(Neonkit::load('
migrations:
directory: /root/migrations
services:
- Doctrine\DBAL\Driver\Mysqli\Driver
- Doctrine\DBAL\Connection([])
'));
$compiler->addDependencies([__FILE__]);
})
->build();

/** @var Configuration $configuration */
$configuration = $container->getByType(Configuration::class);
Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories());
Assert::count(13, $container->findByType(DoctrineCommand::class));
});

Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('migrations', new MigrationsExtension());
$compiler->addConfig(Neonkit::load('
parameters:
appDir: /root
migrations:
directory: %appDir%/migrations
services:
- Doctrine\DBAL\Driver\Mysqli\Driver
- Doctrine\DBAL\Connection([])
'));
$compiler->addDependencies([__FILE__]);
})
->build();

/** @var DependencyFactory $dependencyFactory */
$dependencyFactory = $container->getByType(DependencyFactory::class);
Assert::type(DependencyFactory::class, $dependencyFactory);
Assert::type(DbalMigrationFactory::class, $dependencyFactory->getMigrationFactory());
});
128 changes: 0 additions & 128 deletions tests/Cases/Unit/DI/MigrationsExtensionTest.php

This file was deleted.

19 changes: 0 additions & 19 deletions tests/Toolkit/NeonLoader.php

This file was deleted.

7 changes: 2 additions & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php declare(strict_types = 1);

use Ninjify\Nunjuck\Environment;
use Contributte\Tester\Environment;

if (@!include __DIR__ . '/../vendor/autoload.php') {
echo 'Install Nette Tester using `composer update --dev`';
exit(1);
}

// Configure environment
Environment::setupTester();
Environment::setupTimezone();
Environment::setupVariables(__DIR__);
Environment::setup(__DIR__);

0 comments on commit 5b9c3fd

Please sign in to comment.