PlainTextTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace EasySwoole\DoctrineAnnotation\Tests;
  3. use EasySwoole\DoctrineAnnotation\AnnotationReader;
  4. use EasySwoole\DoctrineAnnotation\Tests\Tag\NonePropertyTag;
  5. use EasySwoole\DoctrineAnnotation\Tests\Tag\PropertyTag;
  6. use PHPUnit\Framework\TestCase;
  7. class PlainTextTest extends TestCase
  8. {
  9. /**
  10. * @PropertyTag(input={"code":2})
  11. * @PropertyTag(input=r"{"code":2,"result":[{"name":1}]}")
  12. */
  13. private $property1;
  14. /**
  15. * @NonePropertyTag({"code":2})
  16. * @NonePropertyTag(r"{"code":2,"result":[{"name":1}]}")
  17. */
  18. private $property2;
  19. private $ref;
  20. private $reader;
  21. function __construct($name = null, array $data = [], $dataName = '')
  22. {
  23. new NonePropertyTag();
  24. new PropertyTag();
  25. $this->ref = new \ReflectionClass(static::class);
  26. $this->reader = new AnnotationReader();
  27. parent::__construct($name, $data, $dataName);
  28. }
  29. function testProperty()
  30. {
  31. $ret = $this->reader->getPropertyAnnotations($this->ref->getProperty('property1'));
  32. $this->assertIsArray($ret);
  33. $this->assertEquals(2,count($ret));
  34. $this->assertEquals(["code"=>2],$ret[0]->input);
  35. $this->assertEquals('{"code":2,"result":[{"name":1}]}',$ret[1]->input);
  36. }
  37. function testNoneProperty()
  38. {
  39. $ret = $this->reader->getPropertyAnnotations($this->ref->getProperty('property2'));
  40. $this->assertIsArray($ret);
  41. $this->assertEquals(2,count($ret));
  42. $this->assertEquals(["code"=>2],$ret[0]->value);
  43. $this->assertEquals('{"code":2,"result":[{"name":1}]}',$ret[1]->value);
  44. }
  45. }