-
-
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.
Interfaces can have properties hooks
- Loading branch information
Showing
3 changed files
with
65 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\PhpGenerator - PHP 8.4 property hooks for interfaces | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\PhpGenerator\InterfaceType; | ||
use Nette\PhpGenerator\PhpFile; | ||
use Nette\PhpGenerator\PropertyHook; | ||
use Nette\PhpGenerator\PsrPrinter; | ||
use Nette\PhpGenerator\Type; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
$file = new PhpFile; | ||
$file->setStrictTypes(); | ||
|
||
$namespace = $file->addNamespace('Abc'); | ||
|
||
$interface = new InterfaceType('HasAuthor'); | ||
|
||
// This will not be printed because it does not have any hooks | ||
$interface->addProperty('isVisible') | ||
->setType(Type::Bool) | ||
->setPublic(); | ||
|
||
$interface->addProperty('score') | ||
->setType(Type::Int) | ||
->setPublic() | ||
->setGetHook(new PropertyHook); | ||
|
||
$interface->addProperty('author') | ||
->setType('Author') | ||
->setPublic() | ||
->setGetHook(new PropertyHook) | ||
->setSetHook(new PropertyHook); | ||
|
||
$expected = <<<'PHP' | ||
interface HasAuthor | ||
{ | ||
public int $score { get; } | ||
public Author $author { set; get; } | ||
} | ||
PHP; | ||
|
||
same(rtrim($expected), rtrim((new PsrPrinter)->printClass($interface))); |