Skip to content

Commit

Permalink
Cleanup codestyle in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkan committed Jul 25, 2024
1 parent ba15dcf commit 99942d1
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 91 deletions.
2 changes: 0 additions & 2 deletions tests/CodeHelper/TernaryOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public function testComplexMultiLine(): void
]),
);

echo FlattenSource::source($t->getSourceArray());

$this->assertSame('$classTest ? $classTest->success(
\'test1\',
\'test2\',
Expand Down
4 changes: 2 additions & 2 deletions tests/Renderer/AssertResultTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

trait AssertResultTrait
{
public function assertSourceResult(array|string $source, string $result)
public function assertSourceResult(array|string $source, string $result): void
{
$file = __DIR__ . '/resources/' . $result .'.result';
$file = __DIR__ . '/resources/' . $result . '.result';
$flattenSource = is_array($source) ? FlattenSource::source($source) : $source;
if (!file_exists($file)) {
echo $flattenSource . PHP_EOL;
Expand Down
7 changes: 5 additions & 2 deletions tests/Renderer/PhpClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function testStripEmptyTypesFromUses(): void
}
}

public function testVariableAttributeFromCtorNotPropegateToSetter(): void
public function testVariableAttributeFromCtorNotPropagateToSetter(): void
{
$class = new PhpClass(Identifier::fromString('Test'));

Expand All @@ -407,6 +407,9 @@ public function testVariableAttributeFromCtorNotPropegateToSetter(): void
$class->addMethod($ctor);

$renderer = new Php8Renderer();
$this->assertSourceResult($renderer->render($class), 'PhpClassTest.testVariableAttributeFromCtorNotPropegateToSetter');
$this->assertSourceResult(
$renderer->render($class),
'PhpClassTest.testVariableAttributeFromCtorNotPropegateToSetter',
);
}
}
14 changes: 7 additions & 7 deletions tests/Renderer/PhpConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class PhpConstantTest extends TestCase
{
public function testSimpleConstantWithoutValue()
public function testSimpleConstantWithoutValue(): void
{
$const = PhpConstant::private('test');

Expand All @@ -17,7 +17,7 @@ public function testSimpleConstantWithoutValue()
$this->assertSame(['private const TEST = \'test\';'], $render->renderConstant($const));
}

public function testArrayConstant()
public function testArrayConstant(): void
{
$const = PhpConstant::protected('test', [
'test' => 1,
Expand All @@ -36,7 +36,7 @@ public function testArrayConstant()
], $render->renderConstant($const));
}

public function testLowerCase()
public function testLowerCase(): void
{
$const = new PhpConstant(
access: PhpConstant::PROTECTED_ACCESS,
Expand All @@ -48,7 +48,7 @@ public function testLowerCase()
$this->assertSame(['protected const test = \'test\';'], $render->renderConstant($const));
}

public function testNoCase()
public function testNoCase(): void
{
$const = new PhpConstant(
access: PhpConstant::PUBLIC_ACCESS,
Expand All @@ -60,15 +60,15 @@ public function testNoCase()
$this->assertSame(['public const testCase = \'testCase\';'], $render->renderConstant($const));
}

public function testUpperCaseNoTransform()
public function testUpperCaseNoTransform(): void
{
$const = PhpConstant::public(identifier: 'TEST_CASE');
$render = new Php7Renderer();

$this->assertSame(['public const TEST_CASE = \'TEST_CASE\';'], $render->renderConstant($const));
}

public function testChangeCase()
public function testChangeCase(): void
{
$const = new PhpConstant(
access: PhpConstant::PROTECTED_ACCESS,
Expand All @@ -84,7 +84,7 @@ public function testChangeCase()
$this->assertSame(['protected const TEST = \'test\';'], $render->renderConstant($const));
}

public function testChangeValue()
public function testChangeValue(): void
{
$const = PhpConstant::public(identifier: 'TEST_CASE');
$const->setValue('test_value');
Expand Down
18 changes: 9 additions & 9 deletions tests/Renderer/PhpDocCommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ final class PhpDocCommentTest extends TestCase
{
use AssertResultTrait;

public function testVarBlock()
public function testVarBlock(): void
{
$comment = PhpDocComment::var(Type::fromString('string'));
$renderer = new Php7Renderer();

$this->assertSame(['/** @var string */'], $renderer->renderComment($comment));
}

public function testWithDescription()
public function testWithDescription(): void
{
$comment = new PhpDocComment('Test Description');
$comment->setParams(PhpDocElementFactory::getParam('int', '$param', 'test desc'));
Expand All @@ -30,7 +30,7 @@ public function testWithDescription()
$this->assertSourceResult($renderer->renderComment($comment), 'PhpDocCommentTest.' . __FUNCTION__);
}

public function testWithoutDescription()
public function testWithoutDescription(): void
{
$comment = new PhpDocComment();
$comment->setParams(PhpDocElementFactory::getParam('int', '$param', 'test desc'));
Expand All @@ -40,23 +40,23 @@ public function testWithoutDescription()
$this->assertSourceResult($renderer->renderComment($comment), 'PhpDocCommentTest.' . __FUNCTION__);
}

public function testOnlyDescription()
public function testOnlyDescription(): void
{
$comment = new PhpDocComment('test');

$renderer = new Php7Renderer();
$this->assertSourceResult($renderer->renderComment($comment), 'PhpDocCommentTest.' . __FUNCTION__);
}

public function testEmpty()
public function testEmpty(): void
{
$comment = new PhpDocComment();
$renderer = new Php7Renderer();

$this->assertCount(0, $renderer->renderComment($comment));
}

public function testDeprecation()
public function testDeprecation(): void
{
$deprecated = PhpDocElementFactory::getDeprecated('use X instead');
$comment = new PhpDocComment();
Expand All @@ -66,7 +66,7 @@ public function testDeprecation()
$this->assertSourceResult($renderer->renderComment($comment), 'PhpDocCommentTest.' . __FUNCTION__);
}

public function testLicense()
public function testLicense(): void
{
$info = 'https://github.com/stefnadev/log/blob/develop/LICENSE.md MIT Licence';
$licence = PhpDocElementFactory::getLicence($info);
Expand All @@ -77,7 +77,7 @@ public function testLicense()
$this->assertSourceResult($renderer->renderComment($comment), 'PhpDocCommentTest.' . __FUNCTION__);
}

public function testGenerated()
public function testGenerated(): void
{
$licence = PhpDocElementFactory::getGenerated('From X');
$comment = new PhpDocComment();
Expand All @@ -91,7 +91,7 @@ public function testGenerated()
], $renderer->renderComment($comment));
}

public function testCheckForParamInCommentAndRemove()
public function testCheckForParamInCommentAndRemove(): void
{
$comment = new PhpDocComment('Test Description');
$comment->setParams(
Expand Down
9 changes: 3 additions & 6 deletions tests/Renderer/PhpEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Stefna\PhpCodeBuilder\Tests\Renderer;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Stefna\PhpCodeBuilder\PhpEnum;
use Stefna\PhpCodeBuilder\Renderer\Php74Renderer;
Expand All @@ -15,19 +16,15 @@ class PhpEnumTest extends TestCase
{
use AssertResultTrait;

/**
* @dataProvider enumTypes
*/
#[DataProvider('enumTypes')]
public function testPhp7(PhpEnum $enum, string $expectedFile): void
{
$renderer = new Php74Renderer();

$this->assertSourceResult($renderer->render($enum), 'PhpEnumTest.' . __FUNCTION__ . '.' . $expectedFile);
}

/**
* @dataProvider enumTypes
*/
#[DataProvider('enumTypes')]
public function testPhp81(PhpEnum $enum, string $expectedFile): void
{
$renderer = new Php81Renderer();
Expand Down
2 changes: 1 addition & 1 deletion tests/Renderer/PhpFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class PhpFileTest extends TestCase
{
use AssertResultTrait;

public function testSingleClassFile()
public function testSingleClassFile(): void
{
$class = new PhpClass(
Identifier::fromString(Test\TestClass::class),
Expand Down
16 changes: 8 additions & 8 deletions tests/Renderer/PhpFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class PhpFunctionTest extends TestCase
{
use AssertResultTrait;

public function testSimpleFunction()
public function testSimpleFunction(): void
{
$func = new PhpFunction(
'testFunction',
Expand All @@ -39,7 +39,7 @@ public function testSimpleFunction()
$this->assertSourceResult($renderer->renderFunction($func), 'PhpFunctionTest.' . __FUNCTION__);
}

public function testFunctionWithMoreThan3Params()
public function testFunctionWithMoreThan3Params(): void
{
$param3 = new PhpParam('test3', Type::fromString('string'));
$func = (new PhpFunction(
Expand All @@ -61,7 +61,7 @@ public function testFunctionWithMoreThan3Params()
$this->assertSourceResult($renderer->render($func), 'PhpFunctionTest.' . __FUNCTION__);
}

public function testFunctionModifyParam()
public function testFunctionModifyParam(): void
{
$func = new PhpFunction(
'testFunction',
Expand All @@ -87,7 +87,7 @@ public function testFunctionModifyParam()
$this->assertSourceResult($renderer->renderFunction($func), 'PhpFunctionTest.' . __FUNCTION__);
}

public function testCloneHandlingParams()
public function testCloneHandlingParams(): void
{
$func = new PhpFunction('testFunction', [
new PhpParam('test', Type::fromString('string')),
Expand All @@ -102,7 +102,7 @@ public function testCloneHandlingParams()
);
}

public function testLegacyFunctionTestSimple()
public function testLegacyFunctionTestSimple(): void
{
$func = new PhpFunction('test', [
new PhpParam('foo', Type::fromString('string|int')),
Expand All @@ -123,7 +123,7 @@ public function testLegacyFunctionTestSimple()
], $renderer->renderFunction($func));
}

public function testLegacyFunctionTestWithoutReturnType()
public function testLegacyFunctionTestWithoutReturnType(): void
{
$func = new PhpFunction('test', [
new PhpParam('foo', Type::fromString('string|int')),
Expand All @@ -142,7 +142,7 @@ public function testLegacyFunctionTestWithoutReturnType()
], $renderer->renderFunction($func));
}

public function testLegacyFunctionTestComplexSource()
public function testLegacyFunctionTestComplexSource(): void
{
$func = new PhpFunction('test', [
new PhpParam('foo', Type::fromString('string|int')),
Expand All @@ -169,7 +169,7 @@ function test($foo): int
', FlattenSource::source($renderer->renderFunction($func)));
}

public function testLegacyFunctionTestMultilineParams()
public function testLegacyFunctionTestMultilineParams(): void
{
$func = new PhpFunction('test', [
new PhpParam('fooIpsumLong', Type::fromString('string')),
Expand Down
19 changes: 8 additions & 11 deletions tests/Renderer/PhpInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Stefna\PhpCodeBuilder\Tests\Renderer;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Stefna\PhpCodeBuilder\PhpClass;
use Stefna\PhpCodeBuilder\PhpConstant;
Expand All @@ -19,7 +20,7 @@ final class PhpInterfaceTest extends TestCase
{
use AssertResultTrait;

public function testSimpleInterface()
public function testSimpleInterface(): void
{
$interface = new PhpInterface(Identifier::fromString(\Test\TestInterface::class));
$interface->addMethod(PhpMethod::public('testMethod', [], []));
Expand All @@ -29,7 +30,7 @@ public function testSimpleInterface()
$this->assertSourceResult($renderer->renderInterface($interface), 'PhpInterfaceTest.' . __FUNCTION__);
}

public function testExtendSingleInterface()
public function testExtendSingleInterface(): void
{
$interface = new PhpInterface(Identifier::fromString(\Test\TestInterface::class));
$interface->addMethod(PhpMethod::public('testMethod', [], []));
Expand All @@ -40,7 +41,7 @@ public function testExtendSingleInterface()
$this->assertSourceResult($renderer->renderInterface($interface), 'PhpInterfaceTest.' . __FUNCTION__);
}

public function testExtendMultipleInterface()
public function testExtendMultipleInterface(): void
{
$interface = new PhpInterface(Identifier::fromString(\Test\TestInterface::class));
$interface->addMethod(PhpMethod::public('testMethod', [], []));
Expand All @@ -53,7 +54,7 @@ public function testExtendMultipleInterface()
$this->assertSourceResult($renderer->renderInterface($interface), 'PhpInterfaceTest.' . __FUNCTION__);
}

public function testInterfaceWithEverything()
public function testInterfaceWithEverything(): void
{
$interface = new PhpInterface(Identifier::fromString(\Test\TestInterface::class));
$interface->addMethod(PhpMethod::public('testMethod', [], []));
Expand All @@ -71,12 +72,10 @@ public function testInterfaceWithEverything()
$this->assertSourceResult($renderer->render($interface), 'PhpInterfaceTest.' . __FUNCTION__);
}

/**
* @dataProvider privateProtectedStuff
*/
#[DataProvider('privateProtectedStuff')]
public function testAddingPrivateStuffToInterface(
PhpVariable|PhpConstant|PhpMethod $stuff,
) {
): void {
$interface = new PhpInterface(Identifier::fromString(\Test\TestInterface::class));

$this->expectException(\BadMethodCallException::class);
Expand All @@ -92,9 +91,7 @@ public function testAddingPrivateStuffToInterface(
}
}

/**
* @dataProvider privateProtectedStuff
*/
#[DataProvider('privateProtectedStuff')]
public function testAddingPrivateStuffToInterfaceWithConvert(
PhpVariable|PhpConstant|PhpMethod $stuff,
): void {
Expand Down
Loading

0 comments on commit 99942d1

Please sign in to comment.