-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
147 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/NamespaceTranslatorTests/Loaders/TranslationClass/GetTranslationArrayTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Wavevision\NamespaceTranslatorTests\Loaders\TranslationClass; | ||
|
||
use Nette\SmartObject; | ||
use PhpParser\Node\Expr\Array_; | ||
use Wavevision\NamespaceTranslator\Exceptions\InvalidState; | ||
use Wavevision\NamespaceTranslator\Loaders\TranslationClass\InjectGetTranslationArray; | ||
use Wavevision\NetteTests\TestCases\DIContainerTestCase; | ||
|
||
class GetTranslationArrayTest extends DIContainerTestCase | ||
{ | ||
|
||
use SmartObject; | ||
use InjectGetTranslationArray; | ||
|
||
public function test(): void | ||
{ | ||
$this->assertInstanceOf( | ||
Array_::class, | ||
$this->getTranslationArray->process(__DIR__ . '/../../App/Models/Translated/Translations/Cs.php') | ||
); | ||
} | ||
|
||
public function testMissingDefine(): void | ||
{ | ||
$this->exception(__DIR__ . '/Resources/InvalidName.php', "TranslationClass must contains function 'define'."); | ||
} | ||
|
||
public function testMissingFlags(): void | ||
{ | ||
$this->exception(__DIR__ . '/Resources/InvalidFlags.php', "Define function must be public and static."); | ||
} | ||
|
||
public function testInvalidReturn(): void | ||
{ | ||
$this->exception(__DIR__ . '/Resources/InvalidReturn.php', "Define function must return an array."); | ||
} | ||
|
||
public function testInvalidBody(): void | ||
{ | ||
$this->exception(__DIR__ . '/Resources/InvalidBody.php', "Define function must have exactly one statement."); | ||
} | ||
|
||
public function testNoFunction(): void | ||
{ | ||
$this->exception(__DIR__ . '/Resources/NoMethod.php', 'No class method found.'); | ||
} | ||
|
||
private function exception(string $file, string $message): void | ||
{ | ||
$this->expectException(InvalidState::class); | ||
$this->expectExceptionMessage($message); | ||
$this->getTranslationArray->process($file); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
tests/NamespaceTranslatorTests/Loaders/TranslationClass/Resources/InvalidBody.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Wavevision\NamespaceTranslatorTests\Loaders\TranslationClass\Resources; | ||
|
||
class InvalidBody | ||
{ | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public static function define(): array | ||
{ | ||
$a = 'hello'; | ||
return [$a => $a]; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tests/NamespaceTranslatorTests/Loaders/TranslationClass/Resources/InvalidFlags.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Wavevision\NamespaceTranslatorTests\Loaders\TranslationClass\Resources; | ||
|
||
class InvalidFlags | ||
{ | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function define(): array | ||
{ | ||
return []; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tests/NamespaceTranslatorTests/Loaders/TranslationClass/Resources/InvalidName.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Wavevision\NamespaceTranslatorTests\Loaders\TranslationClass\Resources; | ||
|
||
class InvalidName | ||
{ | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public static function hello(): array | ||
{ | ||
return []; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
tests/NamespaceTranslatorTests/Loaders/TranslationClass/Resources/InvalidReturn.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Wavevision\NamespaceTranslatorTests\Loaders\TranslationClass\Resources; | ||
|
||
class InvalidReturn | ||
{ | ||
|
||
public static function define(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
tests/NamespaceTranslatorTests/Loaders/TranslationClass/Resources/NoMethod.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Wavevision\NamespaceTranslatorTests\Loaders\TranslationClass\Resources; | ||
|
||
class NoMethod | ||
{ | ||
|
||
} |