Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions tests/Acceptance/Common/CaseTemplatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

namespace Cycle\Testing\Tests\Acceptance\Common;

use Cycle\Testing\Database\DatabasePlugin;
use Cycle\Testing\Config;
use Cycle\Testing\Database\DatabaseTestCase;
use Cycle\Testing\Database\Internal\Current;
use Cycle\Testing\ORM\OrmPlugin;
use Cycle\Testing\Regression\CaseGenerator;
use Cycle\Testing\Regression\TemplateSet;
use Cycle\Testing\Regression\Command;
use Testo\Application\Application;
use Testo\Application\Config\ApplicationConfig;
use Testo\Application\Config\FinderConfig;
use Testo\Application\Config\SuiteConfig;
use Testo\Assert;
use Testo\Core\Context\TestResult;
use Testo\Core\Value\Status;
Expand Down Expand Up @@ -68,21 +64,29 @@ private static function remove(string $dir): void
\rmdir($dir);
}

/**
* The way a user adds a case: `cycle-testing new-case`, then a `testo.php` with a regression suite.
*/
private function assertGeneratedCasePasses(string $template): void
{
$this->dir = \sys_get_temp_dir() . '/cycle-testing-case-' . \bin2hex(\random_bytes(4));
# A fresh namespace per run: the classes of a generated case stay loaded for the rest of the process.
$namespace = 'Cycle\Testing\Tests\Generated\Run' . \bin2hex(\random_bytes(4)) . '\Issue1';
$files = (new CaseGenerator())->generate(TemplateSet::load($template), "{$this->dir}/Issue1", $namespace);
Assert::notBlank($files);
$namespace = 'Cycle\Testing\Tests\Generated\Run' . \bin2hex(\random_bytes(4));
$output = \fopen('php://memory', 'w+');

$code = (new Command($this->dir, $output, $output))
->run(['new-case', '1', "--template={$template}", "--namespace={$namespace}"]);

\rewind($output);
Assert::string((string) \stream_get_contents($output))->startsWith('Created tests/Regression/Issue1 ');
Assert::same($code, 0);

$outer = Current::$pool;
try {
$result = Application::createFromConfig(new ApplicationConfig(suites: [new SuiteConfig(
name: 'Generated',
location: new FinderConfig(["{$this->dir}/Issue1"]),
plugins: [new DatabasePlugin($this->driver), new OrmPlugin()],
)]))->run();
$config = Config::forPackage('cycle/generated', src: [], root: $this->dir)
->regression('tests/Regression', drivers: [$this->driver], plugins: [new OrmPlugin()])
->build();
$result = Application::createFromConfig($config)->run();
} finally {
# The nested suite clears the static the outer suite's assertions read.
Current::$pool = $outer;
Expand Down
19 changes: 19 additions & 0 deletions tests/Fixtures/HarnessSuite/Inline/InlineCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Cycle\Testing\Tests\Fixtures\HarnessSuite\Inline;

use Testo\Inline\TestInline;

/**
* An inline test: a case of another type than `test`, which the driver filters leave alone.
*/
final class InlineCase
{
#[TestInline([2], 4)]
public static function double(int $value): int
{
return $value * 2;
}
}
16 changes: 16 additions & 0 deletions tests/Unit/HarnessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ public function isolationHoldsOnADatabaseFile(): void
self::assertAllPassed($results);
}

public function inlineTestsRunInADriverSuite(): void
{
$results = self::run(['Fixtures/HarnessSuite/Inline'], [new DatabasePlugin(Driver::SQLite)]);

self::assertAllPassed($results);
Assert::count($results, 1);
}

public function ormPluginWithoutADatabaseLeavesTestsAlone(): void
{
$results = self::run(['Fixtures/HarnessSuite/Functions'], [new OrmPlugin()]);

self::assertAllPassed($results);
Assert::count($results, 1);
}

public function queriesGoToTheQuerySqlChannel(): void
{
$results = self::run(['Fixtures/HarnessSuite/Memory'], [new DatabasePlugin(Driver::SQLite)]);
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/HeapIntegrityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Cycle\Testing\Tests\Unit;

use Cycle\ORM\EntityManager;
use Cycle\ORM\Heap\HeapInterface;
use Cycle\ORM\Heap\Node;
use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\ORMInterface;
use Cycle\ORM\Reference\Reference;
Expand Down Expand Up @@ -300,6 +302,40 @@ public function collectionsAreComparedAsLists(): void
Assert::same($violations, ['Entity and State are not in sync `post`.`author`']);
}

public function heapEntityWithoutANodeIsReported(): void
{
$heap = new class implements HeapInterface, \IteratorAggregate {
public function getIterator(): \Iterator
{
return new \ArrayIterator([new User()]);
}

public function has(object $entity): bool
{
return false;
}

public function get(object $entity): ?Node
{
return null;
}

public function find(string $role, array $scope): ?object
{
return null;
}

public function attach(object $entity, Node $node, array $index = []): void {}

public function detach(object $entity): void {}

public function clean(): void {}
};
$orm = Memory::orm(UserSchema::schema())->with(heap: $heap);

Assert::same(HeapIntegrity::violations($orm), ['No node for a heap entity of class ' . User::class . '.']);
}

/**
* @return array{ORMInterface, User}
*/
Expand Down
Loading