File tree Expand file tree Collapse file tree 6 files changed +111
-0
lines changed Expand file tree Collapse file tree 6 files changed +111
-0
lines changed Original file line number Diff line number Diff line change 1+ build
2+ vendor
3+ composer.lock
Original file line number Diff line number Diff line change 1+ C:37:"PHPUnit\Runner\DefaultTestResultCache":339:{a:2:{s:7:"defects";a:1:{s:85:"Manojksrivastava\ChuckNorrisJokes\Tests\JokeFactoryTest::it_returns_a_predefined_joke";i:4;}s:5:"times";a:2:{s:81:"Manojksrivastava\ChuckNorrisJokes\Tests\JokeFactoryTest::it_returns_a_random_joke";d:0.029;s:85:"Manojksrivastava\ChuckNorrisJokes\Tests\JokeFactoryTest::it_returns_a_predefined_joke";d:0.003;}}}
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " manojksrivastava/chuck-norris-jokes" ,
3+ "description" : " Create random Chuck Norris jokes" ,
4+ "type" : " library" ,
5+ "license" : " MIT" ,
6+ "authors" : [
7+ {
8+ "name" : " Manoj K Srivastava" ,
9+ "email" : " manoj.srivastava@gmail.com"
10+ }
11+ ],
12+ "require" : {},
13+ "autoload" : {
14+ "psr-4" :{"Manojksrivastava\\ ChuckNorrisJokes\\ " : " src/"
15+ }
16+ },
17+ "autoload-dev" : {
18+ "psr-4" :{"Manojksrivastava\\ ChuckNorrisJokes\\ Tests\\ " : " tests"
19+ }
20+ },
21+ "require-dev" : {
22+ "phpunit/phpunit" : " ^9.5"
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <phpunit bootstrap =" vendor/autoload.php"
3+ backupGlobals =" false"
4+ backupStaticAttributes =" false"
5+ colors =" true"
6+ verbose =" true"
7+ convertErrorsToExceptions =" true"
8+ convertNoticesToExceptions =" true"
9+ convertWarningsToExceptions =" true"
10+ processIsolation =" false"
11+ stopOnFailure =" false" >
12+ <testsuites >
13+ <testsuite name =" Chuck Norris Test Suite" >
14+ <directory >tests</directory >
15+ </testsuite >
16+ </testsuites >
17+ <filter >
18+ <whitelist >
19+ <directory suffix =" .php" >src/</directory >
20+ </whitelist >
21+ </filter >
22+ <logging >
23+ <log type =" tap" target =" build/report.tap" />
24+ <log type =" junit" target =" build/report.junit.xml" />
25+ <log type =" coverage-html" target =" build/coverage" charset =" UTF-8" yui =" true" highlight =" true" />
26+ <log type =" coverage-text" target =" build/coverage.txt" />
27+ <log type =" coverage-clover" target =" build/logs/clover.xml" />
28+ </logging >
29+ </phpunit >
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Manojksrivastava \ChuckNorrisJokes ;
3+ class JokeFactory
4+ {
5+ protected $ jokes = [
6+ 'Chuck Norris doesn\’t read books. He stares them down until he gets the information he wants. ' ,
7+ 'Time waits for no man. Unless that man is Chuck Norris. ' ,
8+ 'When God said, “Let there be light!” Chuck said, “Say Please.” '
9+ ];
10+
11+ public function __construct (array $ jokes = null )
12+ {
13+ if ($ jokes ) {
14+ $ this ->jokes = $ jokes ;
15+ }
16+ }
17+ public function getRandomJoke ()
18+ {
19+ return $ this ->jokes [array_rand ($ this ->jokes )];
20+ }
21+
22+ }
23+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Manojksrivastava \ChuckNorrisJokes \Tests ;
4+
5+ use Manojksrivastava \ChuckNorrisJokes \JokeFactory ;
6+ use PHPUnit \Framework \TestCase ;
7+
8+ class JokeFactoryTest extends TestCase
9+ {
10+ /** @test */
11+ public function it_returns_a_random_joke ()
12+ {
13+ # code...
14+ $ jokes = new JokeFactory (['This is a joke ' ,]);
15+ $ joke = $ jokes ->getRandomJoke ();
16+ $ this ->assertSame ('This is a joke ' , $ joke );
17+ }
18+ /** @test */
19+ public function it_returns_a_predefined_joke ()
20+ {
21+ $ chuckNorrisJokes = [
22+ 'Chuck Norris doesn\’t read books. He stares them down until he gets the information he wants. ' ,
23+ 'Time waits for no man. Unless that man is Chuck Norris. ' ,
24+ 'When God said, “Let there be light!” Chuck said, “Say Please.” '
25+ ];
26+
27+ $ jokes = new JokeFactory ();
28+ $ joke = $ jokes ->getRandomJoke ();
29+ $ this ->assertContains ($ joke ,$ chuckNorrisJokes );
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments