Skip to content

Commit

Permalink
PHPUnit -> Nette Tester
Browse files Browse the repository at this point in the history
  • Loading branch information
petrparolek authored and f3l1x committed Jan 20, 2021
1 parent 0a64c85 commit a142c46
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -23,7 +23,7 @@ phpstan: ## Analyse code with PHPStan
# Tests

tests: ## Run all tests
vendor/bin/phpunit tests --cache-result-file=tests/tmp/phpunit.cache --colors=always
vendor/bin/tester -s -p php --colors 1 -C tests/cases

coverage: ## Generate code coverage in XML format
phpdbg -qrr vendor/bin/phpunit tests --cache-result-file=tests/tmp/phpunit.cache --colors=always -c tests/coverage.xml
5 changes: 3 additions & 2 deletions composer.json
Expand Up @@ -21,13 +21,13 @@
"nette/http": "^3.0.0",
"nette/security": "^3.0.0",
"nettrine/orm": "^0.5.0",
"ninjify/nunjuck": "^0.3.0",
"ninjify/qa": "^0.11.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-nette": "^0.12",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^8.5|^9.5",
"tracy/tracy": "^2.7.0"
},
"autoload": {
Expand All @@ -37,7 +37,8 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\Nettrine\\Extensions\\KnpLabs\\": "tests/"
"Tests\\Cases\\": "tests/cases",
"Tests\\Fixtures\\": "tests/fixtures"
}
},
"minimum-stability": "dev",
Expand Down
10 changes: 6 additions & 4 deletions ruleset.xml
Expand Up @@ -6,10 +6,12 @@
<!-- Specific -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
src => Nettrine\Extensions\KnpLabs,
tests => Tests\Nettrine\Extensions\KnpLabs,
"/>
<property name="rootNamespaces" type="array">
<element key="src" value="Nettrine\Extensions\KnpLabs"/>
<element key="tests/cases" value="Tests\Cases"/>
<element key="tests/fixtures" value="Tests\Fixtures"/>
<element key="tests/toolkit" value="Tests\Toolkit"/>
</property>
</properties>
</rule>

Expand Down
13 changes: 13 additions & 0 deletions tests/bootstrap.php
@@ -0,0 +1,13 @@
<?php declare(strict_types = 1);

use Ninjify\Nunjuck\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__);
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests\Nettrine\Extensions\KnpLabs\Unit\DI;
namespace Tests\Cases\DI;

use Knp\DoctrineBehaviors\Model\Blameable\Blameable;
use Knp\DoctrineBehaviors\Model\Geocodable\Geocodable;
Expand Down Expand Up @@ -31,11 +31,14 @@
use Nettrine\Extensions\KnpLabs\DI\KnpLabsBehaviorExtension;
use Nettrine\Extensions\KnpLabs\Security\UserCallable;
use Nettrine\Extensions\KnpLabs\Tracy\LoggerCallable;
use PHPUnit\Framework\TestCase;
use Tests\Nettrine\Extensions\KnpLabs\Fixtures\GeolocationPointGetter;
use Tests\Nettrine\Extensions\KnpLabs\Fixtures\LocaleGetter;
use Tester\Assert;
use Tester\TestCase;
use Tests\Fixtures\GeolocationPointGetter;
use Tests\Fixtures\LocaleGetter;
use Tracy\Bridges\Nette\TracyExtension;

require __DIR__ . '/../../bootstrap.php';

final class KnpLabsBehaviorExtensionTest extends TestCase
{

Expand All @@ -50,7 +53,7 @@ public function testDefault(): void
$container = new $class();
assert($container instanceof Container);

$this->assertInstanceOf(ClassAnalyzer::class, $container->getService('nettrine.extensions.knplabs.classAnalyzer'));
Assert::type(ClassAnalyzer::class, $container->getService('nettrine.extensions.knplabs.classAnalyzer'));
}

public function testSimple(): void
Expand All @@ -77,15 +80,15 @@ public function testSimple(): void
$container = new $class();
assert($container instanceof Container);

$this->assertInstanceOf(BlameableSubscriber::class, $container->getService('nettrine.extensions.knplabs.blameable'));
$this->assertInstanceOf(GeocodableSubscriber::class, $container->getService('nettrine.extensions.knplabs.geocodable'));
//$this->assertInstanceOf(LoggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.loggable'));
$this->assertInstanceOf(SluggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sluggable'));
$this->assertInstanceOf(SoftDeletableSubscriber::class, $container->getService('nettrine.extensions.knplabs.softDeletable'));
$this->assertInstanceOf(SortableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sortable'));
$this->assertInstanceOf(TimestampableSubscriber::class, $container->getService('nettrine.extensions.knplabs.timestampable'));
$this->assertInstanceOf(TranslatableSubscriber::class, $container->getService('nettrine.extensions.knplabs.translatable'));
$this->assertInstanceOf(TreeSubscriber::class, $container->getService('nettrine.extensions.knplabs.tree'));
Assert::type(BlameableSubscriber::class, $container->getService('nettrine.extensions.knplabs.blameable'));
Assert::type(GeocodableSubscriber::class, $container->getService('nettrine.extensions.knplabs.geocodable'));
//Assert::type(LoggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.loggable'));
Assert::type(SluggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sluggable'));
Assert::type(SoftDeletableSubscriber::class, $container->getService('nettrine.extensions.knplabs.softDeletable'));
Assert::type(SortableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sortable'));
Assert::type(TimestampableSubscriber::class, $container->getService('nettrine.extensions.knplabs.timestampable'));
Assert::type(TranslatableSubscriber::class, $container->getService('nettrine.extensions.knplabs.translatable'));
Assert::type(TreeSubscriber::class, $container->getService('nettrine.extensions.knplabs.tree'));
}

public function testComplex(): void
Expand Down Expand Up @@ -148,15 +151,17 @@ public function testComplex(): void
$container = new $class();
assert($container instanceof Container);

$this->assertInstanceOf(BlameableSubscriber::class, $container->getService('nettrine.extensions.knplabs.blameable'));
$this->assertInstanceOf(GeocodableSubscriber::class, $container->getService('nettrine.extensions.knplabs.geocodable'));
$this->assertInstanceOf(LoggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.loggable'));
$this->assertInstanceOf(SluggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sluggable'));
$this->assertInstanceOf(SoftDeletableSubscriber::class, $container->getService('nettrine.extensions.knplabs.softDeletable'));
$this->assertInstanceOf(SortableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sortable'));
$this->assertInstanceOf(TimestampableSubscriber::class, $container->getService('nettrine.extensions.knplabs.timestampable'));
$this->assertInstanceOf(TranslatableSubscriber::class, $container->getService('nettrine.extensions.knplabs.translatable'));
$this->assertInstanceOf(TreeSubscriber::class, $container->getService('nettrine.extensions.knplabs.tree'));
Assert::type(BlameableSubscriber::class, $container->getService('nettrine.extensions.knplabs.blameable'));
Assert::type(GeocodableSubscriber::class, $container->getService('nettrine.extensions.knplabs.geocodable'));
Assert::type(LoggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.loggable'));
Assert::type(SluggableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sluggable'));
Assert::type(SoftDeletableSubscriber::class, $container->getService('nettrine.extensions.knplabs.softDeletable'));
Assert::type(SortableSubscriber::class, $container->getService('nettrine.extensions.knplabs.sortable'));
Assert::type(TimestampableSubscriber::class, $container->getService('nettrine.extensions.knplabs.timestampable'));
Assert::type(TranslatableSubscriber::class, $container->getService('nettrine.extensions.knplabs.translatable'));
Assert::type(TreeSubscriber::class, $container->getService('nettrine.extensions.knplabs.tree'));
}

}

(new KnpLabsBehaviorExtensionTest())->run();
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests\Nettrine\Extensions\KnpLabs\Fixtures;
namespace Tests\Fixtures;

use Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point;

Expand Down
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests\Nettrine\Extensions\KnpLabs\Fixtures;
namespace Tests\Fixtures;

final class LocaleGetter
{
Expand Down
12 changes: 12 additions & 0 deletions tests/toolkit/Tests.php
@@ -0,0 +1,12 @@
<?php declare(strict_types = 1);

namespace Tests\Toolkit;

final class Tests
{

public const APP_PATH = __DIR__ . '/..';
public const TEMP_PATH = __DIR__ . '/../tmp';
public const FIXTURES_PATH = __DIR__ . '/../fixtures';

}

0 comments on commit a142c46

Please sign in to comment.