예제 #1
0
 /**
  * @test
  */
 protected static function resetTest()
 {
     $_GET['my_get_var'] = 'get';
     $_POST['my_post_var'] = 'post';
     $_ENV['MY_ENV_VAR'] = 'nice';
     $locale = ["UTF-8", "C", "C", "C", "C", "C/UTF-8/C/C/C/C", "C"];
     $env = new Environment('Europe/Vienna', $locale, E_ALL, $GLOBALS, $_ENV, $_GET, $_POST);
     $_GET['my_get_var'] = 'something else';
     $_POST['my_post_var'] = 'something else';
     $_ENV['MY_ENV_VAR'] = 'something else';
     $env->reset();
     test_flight_assert_same('get', $_GET['my_get_var']);
     test_flight_assert_same('post', $_POST['my_post_var']);
     test_flight_assert_same('nice', $_ENV['MY_ENV_VAR']);
 }
예제 #2
0
 /**
  * @test
  */
 protected static function printExceptionTest()
 {
     $prophet = new \Prophecy\Prophet();
     /** @var WindowHelper $windowHelper */
     $windowHelper = $prophet->prophesize(WindowHelper::class)->reveal();
     /** @var CodeFormatter $codeFormatter */
     $codeFormatter = $prophet->prophesize(CodeFormatter::class)->reveal();
     /** @var MethodDefinition $testDefinition */
     /** @var MethodDefinition|\Prophecy\Prophecy\ObjectProphecy $prophecy */
     $prophecy = $prophet->prophesize(MethodDefinition::class);
     $prophecy->getClassName()->willReturn(__CLASS__);
     $prophecy->getMethodIsStatic()->willReturn(false);
     $prophecy->getMethodName()->willReturn('thisIsTheDummyTestMethodForTheTest');
     $prophecy->getFilePath()->willReturn(__FILE__);
     $testDefinition = $prophecy->reveal();
     $tempOutputStream = fopen('php://memory', 'r+');
     $printer = new static($tempOutputStream, $tempOutputStream, $windowHelper, $codeFormatter);
     $printer->setEnableColoredOutput(false);
     $printer->printException($testDefinition, new \Exception('ExceptionMessage'));
     rewind($tempOutputStream);
     $output = stream_get_contents($tempOutputStream);
     $testString = "\n" . 'Error Exception #0 during test ' . 'Cundd\\TestFlight\\Output\\ExceptionPrinter->thisIsTheDummyTestMethodForTheTest(): ' . "\n" . 'ExceptionMessage';
     test_flight_assert_same($testString, substr($output, 0, strlen($testString)));
 }
    /**
     * @test
     */
    protected static function getPreProcessedCodeTest()
    {
        $file = new \Cundd\TestFlight\FileAnalysis\File('some/path');
        $originalCode = '';
        $definition = new DocumentationCodeDefinition($originalCode, $file);
        test_flight_assert_same('', $definition->getPreProcessedCode());
        $originalCode = '__FILE__';
        $definition = new DocumentationCodeDefinition($originalCode, $file);
        test_flight_assert_same("'some/path'", $definition->getPreProcessedCode());
        $originalCode = '__DIR__';
        $definition = new DocumentationCodeDefinition($originalCode, $file);
        test_flight_assert_same("'some'", $definition->getPreProcessedCode());
        $originalCode = 'assert(true)';
        $definition = new DocumentationCodeDefinition($originalCode, $file);
        test_flight_assert_same('test_flight_assert(true)', $definition->getPreProcessedCode());
        $originalCode = '//assert(true)';
        $definition = new DocumentationCodeDefinition($originalCode, $file);
        test_flight_assert_same('//test_flight_assert(true)', $definition->getPreProcessedCode());
        $originalCode = '
$someValue = true;
assert($someValue)';
        $definition = new DocumentationCodeDefinition($originalCode, $file);
        test_flight_assert_same('
$someValue = true;
test_flight_assert($someValue)', $definition->getPreProcessedCode());
        $originalCode = '\\Cundd\\TestFlight\\Assert::assertSame(true)';
        $definition = new DocumentationCodeDefinition($originalCode, $file);
        test_flight_assert_same('\\Cundd\\TestFlight\\Assert::assertSame(true)', $definition->getPreProcessedCode());
    }
예제 #4
0
    /**
     * @test
     */
    protected function getCodeFromDocumentationTest()
    {
        $documentation = '
Documentation
=============

```php
assert(true);
```

```php
assert(true);

assert(1 < 2);
```
';
        $codeSamples = $this->getCodeFromDocumentation($documentation);
        test_flight_assert_type('array', $codeSamples);
        test_flight_assert_type('string', $codeSamples[0]);
        test_flight_assert_same('assert(true);', $codeSamples[0]);
        test_flight_assert_same('assert(true);

assert(1 < 2);', $codeSamples[1]);
    }