Skip to content

Commit

Permalink
adds interface tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ju1ius committed Dec 27, 2023
1 parent 32afb5d commit 9bd990b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mocks/ChildInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

interface ChildInterface
{
public const int ANYTHING = 0;

public function getAnything(RootInterface $root): int;
}
8 changes: 8 additions & 0 deletions mocks/RootInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

namespace Souplette\Chicot\Mocks;

/**
* Das root.
*/
interface RootInterface
{
/**
* Everything
*/
public const int EVERYTHING = 42;

public function getEverything(): int;
}
60 changes: 60 additions & 0 deletions tests/ExtensionInterfaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php declare(strict_types=1);

namespace Souplette\Chicot\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use ReflectionClass;
use Souplette\Chicot\Mocks\ChildInterface;
use Souplette\Chicot\Mocks\RootInterface;

final class ExtensionInterfaceTest extends GeneratorTestCase
{
#[DataProvider('generateInterfaceProvider')]
public function testGenerateInterface(string $name, string $expected): void
{
$code = self::generateStubs('acme', classes: [
new ReflectionClass($name),
]);
self::assertCodeEq($expected, $code);
}

public static function generateInterfaceProvider(): iterable
{
yield 'interface' => [
RootInterface::class,
<<<'PHP'
/**
* Das root.
*/
interface RootInterface
{
/**
* Everything
*/
public const int EVERYTHING = 42;
public function getEverything() : int;
}
PHP,
];
yield 'child interface' => [
ChildInterface::class,
<<<'PHP'
interface ChildInterface
{
public const int ANYTHING = 0;
public function getAnything(\Souplette\Chicot\Mocks\RootInterface $root) : int;
}
PHP,
];
}

protected static function assertCodeEq(string $expected, string $actual): void
{
$expected = <<<PHP
namespace Souplette\Chicot\Mocks;
{$expected}
PHP;
parent::assertCodeEq($expected, $actual);
}
}

0 comments on commit 9bd990b

Please sign in to comment.