ArgumentAnalysisTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Tokenizer\Analyzer\Analysis;
  13. use PhpCsFixer\Tests\TestCase;
  14. use PhpCsFixer\Tokenizer\Analyzer\Analysis\ArgumentAnalysis;
  15. use PhpCsFixer\Tokenizer\Analyzer\Analysis\TypeAnalysis;
  16. /**
  17. * @author VeeWee <toonverwerft@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Tokenizer\Analyzer\Analysis\ArgumentAnalysis
  22. */
  23. final class ArgumentAnalysisTest extends TestCase
  24. {
  25. public function testWithoutName(): void
  26. {
  27. $analysis = new ArgumentAnalysis(null, null, null, null);
  28. self::assertNull($analysis->getName());
  29. self::assertNull($analysis->getNameIndex());
  30. }
  31. public function testName(): void
  32. {
  33. $analysis = new ArgumentAnalysis('$name', 1, null, null);
  34. self::assertSame('$name', $analysis->getName());
  35. self::assertSame(1, $analysis->getNameIndex());
  36. }
  37. public function testDefault(): void
  38. {
  39. $analysis = new ArgumentAnalysis('$name', 1, 'default', null);
  40. self::assertTrue($analysis->hasDefault());
  41. self::assertSame('default', $analysis->getDefault());
  42. }
  43. public function testNoDefaultFound(): void
  44. {
  45. $analysis = new ArgumentAnalysis('$name', 1, null, null);
  46. self::assertFalse($analysis->hasDefault());
  47. self::assertNull($analysis->getDefault());
  48. }
  49. public function testType(): void
  50. {
  51. $analysis = new ArgumentAnalysis('$name', 1, null, new TypeAnalysis('string', 1, 4));
  52. self::assertTrue($analysis->hasTypeAnalysis());
  53. self::assertSame('string', $analysis->getTypeAnalysis()->getName());
  54. self::assertSame(1, $analysis->getTypeAnalysis()->getStartIndex());
  55. self::assertSame(4, $analysis->getTypeAnalysis()->getEndIndex());
  56. }
  57. public function testNoTypeFound(): void
  58. {
  59. $analysis = new ArgumentAnalysis('$name', 1, null, null);
  60. self::assertFalse($analysis->hasTypeAnalysis());
  61. self::assertNull($analysis->getTypeAnalysis());
  62. }
  63. }