0

一部のプロジェクトで再利用できる単純なライブラリを作成しています。現時点では、いくつかの「愚かな」キャラクターをスマートな同等のものに交換するだけです。とにかく、laravel 4の新しいインスタンスをインストールしてから実行しましphp artisan workbench jonnybarnes/dumbquotesた。次に、 にいくつかのコードを書きましたDumbquotesParser.php。これは現在常駐していますLARAVEL/workbench/jonnybarnes/dumbquotes/src/Jonnybarnes/Dumbquotes/DumbquotesParser.php。そこで、提供された tests フォルダーにこのためのテストファイルを作成しました:

<?php

require __DIR__.'/../src/Jonnybarnes/Dumbquotes/DumbquotesParser.php';

class DumbquotesParserTest extends PHPUnit_Framework_TestCase {
    public function testApostrophe()
    {
        $actual = DumbquotesParser::apostrophe('We\'re testing Jonny\'s apotrophes\' form');
        $expected = 'We’re testing Jonny’s apostrophes’ form';

        $this->assertEquals($actual, $excpected);
    }
}

しかし、うまくいきません。phpunitにパーサーをロードさせる方法が完全にはわかりません。次の出力が得られます。

jonny@jonny-arch:~/dumbquotes-bench/workbench/jonnybarnes/dumbquotes|testing ⇒  ./vendor/bin/phpunit tests
PHPUnit 3.7.21-2-g268d9f1 by Sebastian Bergmann.

Configuration read from /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/phpunit.xml

PHP Fatal error:  Class 'DumbquotesParser' not found in /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/tests/DumbquotesParserTest.php on line 8
PHP Stack trace:
PHP   1. {main}() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/composer/bin/phpunit:63
PHP   3. PHPUnit_TextUI_Command->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705
PHP   7. PHPUnit_Framework_TestSuite->runTest() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
PHP   8. PHPUnit_Framework_TestCase->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
PHP   9. PHPUnit_Framework_TestResult->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:776
PHP  10. PHPUnit_Framework_TestCase->runBare() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648
PHP  11. PHPUnit_Framework_TestCase->runTest() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:831
PHP  12. ReflectionMethod->invokeArgs() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976
PHP  13. DumbquotesParserTest->testApostrophe() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976

Fatal error: Class 'DumbquotesParser' not found in /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/tests/DumbquotesParserTest.php on line 8

Call Stack:
    0.0002     231432   1. {main}() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/composer/bin/phpunit:0
    0.0036     609112   2. PHPUnit_TextUI_Command::main() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/composer/bin/phpunit:63
    0.0036     609344   3. PHPUnit_TextUI_Command->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
    0.0220    2346712   4. PHPUnit_TextUI_TestRunner->doRun() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176
    0.0474    2638864   5. PHPUnit_Framework_TestSuite->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349
    0.0476    2640512   6. PHPUnit_Framework_TestSuite->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705
    0.0477    2641112   7. PHPUnit_Framework_TestSuite->runTest() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
    0.0477    2641144   8. PHPUnit_Framework_TestCase->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
    0.0478    2642352   9. PHPUnit_Framework_TestResult->run() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:776
    0.0510    2700216  10. PHPUnit_Framework_TestCase->runBare() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648
    0.0515    2719488  11. PHPUnit_Framework_TestCase->runTest() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:831
    0.0515    2720768  12. ReflectionMethod->invokeArgs() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976
    0.0515    2720800  13. DumbquotesParserTest->testApostrophe() /home/jonny/dumbquotes-bench/workbench/jonnybarnes/dumbquotes/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976

では、実際にパーサーをロードするにはどうすればよいでしょうか?

テストファイルを次のように変更すると、テストが機能します。

<?php

require __DIR__.'/../src/Jonnybarnes/Dumbquotes/DumbquotesParser.php';


class DumbquotesParserTest extends PHPUnit_Framework_TestCase {
    public function testApostrophe()
    {
        $parser = new \Jonnybarnes\Dumbquotes\DumbquotesParser();
        $actual = $parser->apostrophe('We\'re testing Jonny\'s apostrophes\' form');
        $expected = 'We’re testing Jonny’s apostrophes’ form';

        $this->assertEquals($actual, $expected);
    }
}

$parser = new \...\...\...();すべてのテストを行う必要がありますか?

4

1 に答える 1