diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fd3be8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +vendor +build +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..7792e74 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "bagwaa/really-funny-jokes", + "description": "Just some really funny jokes, clearly what every PHP application needs", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Richard Bagshaw", + "email": "me@richardbagshaw.co.uk" + } + ], + "require": {}, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "autoload": { + "psr-4": { + "Bagwaa\\ReallyFunnyJokes\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Bagwaa\\ReallyFunnyJokes\\Tests\\": "tests/" + } + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..4679a4d --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + tests + + + + + src/ + + + + + + + + + + \ No newline at end of file diff --git a/src/JokeFactory.php b/src/JokeFactory.php new file mode 100644 index 0000000..900d44f --- /dev/null +++ b/src/JokeFactory.php @@ -0,0 +1,39 @@ +jokes = $jokes; + } + } + + /** + * Return a random joke to the caller. + */ + public function getRandomJoke(): string + { + return $this->jokes[array_rand($this->jokes)]; + } +} diff --git a/tests/JokeFactoryTest.php b/tests/JokeFactoryTest.php new file mode 100644 index 0000000..bdf4e52 --- /dev/null +++ b/tests/JokeFactoryTest.php @@ -0,0 +1,41 @@ +getRandomJoke(); + + $this->assertSame('This is a joke', $joke); + } + + /** @test */ + public function itReturnsAPredefinedJoke() + { + $jokes = [ + 'The First rule of Chuck Norris is: you do not talk about Chuck Norris.', + 'Chuck Norris does not wear a condom. Because there is no such thing as protection from Chuck Norris.', + 'Chuck Norris\' tears cure cancer. Too bad he has never cried.', + 'Chuck Norris counted to infinity... Twice.', + 'If you can see Chuck Norris, he can see you. If you can\'t see Chuck Norris you may be only seconds away from death.', + ]; + + $jokeFactory = new JokeFactory(); + $joke = $jokeFactory->getRandomJoke(); + + $this->assertContains($joke, $jokes); + } +}