/
jagepard
/
Rudra-Annotation
Обзор
Документация
Войти
/
jagepard
/
Rudra-Annotation
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/AnnotationTest.php
143 строки
4 KB
Jagepard
fix
23 июн 2026, 13:57
23 июн 2026, 13:57
3e3d417
Код
Авторство
О чём код?
<?php declare(strict_types=1); /** * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * @author Korotkov Danila (Jagepard) <jagepard@yandex.ru> * @license https://mozilla.org/MPL/2.0/ MPL-2.0 */ namespace Rudra\Annotation\Tests; use Rudra\Annotation\Annotation; use Rudra\Annotation\AnnotationInterface; use Rudra\Annotation\Tests\Stub\PageController; class AnnotationTest extends \PHPUnit\Framework\TestCase { private AnnotationInterface $annotation; private string $docBlock = " /** * @Routing(url = '') * @Defaults(name='user1', lastname = 'sample', age='0', address = {country : 'Russia'; state : 'Tambov'}, phone = '000-00000000') * @assertResult(false) * @Validate(name = 'min:150', phone = 'max:9') * @Middleware('Middleware', params = {int1 : '123'}) * @Annotation(param1, param2 = 'param2', param3={param1;param2:'param2'}) */ "; private array $result = [ "Routing" => [["url" => ""]], "Defaults" => [ [ "name" => "user1", "lastname" => "sample", "age" => "0", "address" => [ "country" => "Russia", "state" => "Tambov", ], "phone" => "000-00000000", ], ], "assertResult" => [["false"]], "Validate" => [ [ "name" => "min:150", "phone" => "max:9", ], ], "Middleware" => [ [ "'Middleware'", "params" => [ "int1" => "123", ], ], ], "Annotation" => [ [ "param1", "param2" => "param2", "param3" => [ "param1", "param2" => "param2", ], ], ], ]; protected function setUp(): void { $this->annotation = new Annotation(); } private function getMethod(string $name): \ReflectionMethod { $class = new \ReflectionClass($this->annotation); $method = $class->getMethod($name); $method->setAccessible(true); return $method; } public function testParseAnnotations(): void { $parseAnnotations = $this->getMethod("parseAnnotations"); $this->assertEquals($this->result, $parseAnnotations->invokeArgs($this->annotation, [$this->docBlock])); } public function testGetClassAnnotations(): void { $this->assertEquals($this->result, $this->annotation->getAnnotations(PageController::class)); } public function testGetMethodAnnotations(): void { $this->assertEquals($this->result, $this->annotation->getAnnotations(PageController::class, "indexAction")); } public function testGetClassAttributes(): void { $this->assertEquals($this->result, $this->annotation->getAttributes(PageController::class)); } public function testGetMethodAttributes(): void { $this->assertEquals($this->result, $this->annotation->getAttributes(PageController::class, "secondAction")); } public function testGetMethodWithoutAnnotations(): void { $this->assertEquals([], $this->annotation->getAnnotations(PageController::class, "withoutDocblock")); } public function testParseAnnotationsWithEqualsInValue(): void { $docBlock = " /** * @Routing(url='site/com?a=1&b=2', method='GET') * @Validate(pattern='^[a-z]+=[0-9]+$') */ "; $expected = [ "Routing" => [ [ "url" => "site/com?a=1&b=2", "method" => "GET", ], ], "Validate" => [ [ "pattern" => "^[a-z]+=[0-9]+$", ], ], ]; $parseAnnotations = $this->getMethod("parseAnnotations"); $this->assertEquals($expected, $parseAnnotations->invokeArgs($this->annotation, [$docBlock])); } }