-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
176 additions
and
34 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
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
46 changes: 46 additions & 0 deletions
46
tests/PhpGenerator/ClassManipulator.implementInterface.84.phpt
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,46 @@ | ||
<?php | ||
|
||
/** | ||
* @phpVersion 8.4 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\PhpGenerator\ClassManipulator; | ||
use Nette\PhpGenerator\ClassType; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
interface TestInterface | ||
{ | ||
public array $bar { get; } | ||
|
||
public function testMethod(); | ||
} | ||
|
||
$class = new ClassType('TestClass'); | ||
$manipulator = new ClassManipulator($class); | ||
|
||
// Test valid interface implementation | ||
$manipulator->implementInterface(TestInterface::class); | ||
Assert::match(<<<'XX' | ||
class TestClass implements TestInterface | ||
{ | ||
public array $bar; | ||
function testMethod() | ||
{ | ||
} | ||
} | ||
|
||
XX, (string) $class); | ||
|
||
|
||
// Test exception for non-interface | ||
Assert::exception( | ||
fn() => $manipulator->implementInterface(stdClass::class), | ||
InvalidArgumentException::class, | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\PhpGenerator\InterfaceType; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
Assert::exception(function () { | ||
$interface = new InterfaceType('Demo'); | ||
$interface->addProperty('first', 123); | ||
$interface->validate(); | ||
}, Nette\InvalidStateException::class, 'Property Demo::$first: Interface cannot have initialized properties.'); | ||
|
||
Assert::exception(function () { | ||
$interface = new InterfaceType('Demo'); | ||
$interface->addProperty('first'); | ||
$interface->validate(); | ||
}, Nette\InvalidStateException::class, 'Property Demo::$first: Interface cannot have properties without hooks.'); |
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