@Symfony.test-in.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Acme;
  11. declare(ticks=1);
  12. /**
  13. * Coding standards demonstration.
  14. */
  15. class FooBar
  16. {
  17. const SOME_CONST = 42;
  18. private $fooBar;
  19. /**
  20. * @param string $dummy Some argument description
  21. */
  22. public function __construct($dummy)
  23. {{
  24. $this->fooBar = $this->transformText($dummy);
  25. }}
  26. /**
  27. * Foo
  28. *
  29. * @param string $dummy Some argument description
  30. * @param array $options
  31. * @param string|null $data Foo
  32. * @throws \RuntimeException
  33. * @return string|null Transformed input
  34. */
  35. private function transformText($dummy, array $options = array(),$data=null)
  36. {
  37. $fnc = function () { return true; };
  38. $mergedOptions = array_merge(
  39. array(
  40. 'some_default' => 'values',
  41. 'another_default' => 'more values',
  42. ),
  43. $options
  44. );
  45. if (true === $dummy) {
  46. return;
  47. }
  48. if ('string' === $dummy) {
  49. if ('values' === $mergedOptions['some_default']) {
  50. return substr($dummy, 0, 5);
  51. }
  52. return ucwords($dummy);
  53. }
  54. throw new \RuntimeException(sprintf('Unrecognized dummy option "%s".', $dummy));
  55. }
  56. private function reverseBoolean($value = null, $theSwitch = false)
  57. {
  58. if (!$theSwitch) {
  59. return;
  60. }
  61. return !$value;
  62. }
  63. /**
  64. * @param string $text
  65. * @return string
  66. */
  67. private function printText($text)
  68. {
  69. echo $text;
  70. }
  71. }
  72. interface Test1Interface
  73. {
  74. }
  75. interface Test2Interface
  76. {
  77. }
  78. class FooBarTest extends
  79. \PHPUnit_Framework_TestCase
  80. implements
  81. Test1Interface,
  82. Test2Interface
  83. {
  84. /**
  85. * @expectedException Exception
  86. */
  87. public function testFooBar($a)
  88. {
  89. $b = $a === 1 ? 'a' : 'b';
  90. echo $b;;
  91. }
  92. }
  93. final class FinalClass
  94. {
  95. final function finalMethod(){}
  96. }
  97. function callback($a, ... $b) { return (-- $a) * ($b ++);}
  98. $a =& $b;
  99. $c = & $d;
  100. echo 1 ?>