-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c3e88eb
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor | ||
build | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]" | ||
} | ||
], | ||
"require": {}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Bagwaa\\ReallyFunnyJokes\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Bagwaa\\ReallyFunnyJokes\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Joke Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-text" target="build/coverage.txt" /> | ||
<log type="coverage-clover" target="build/logs/clover.xml" /> | ||
</logging> | ||
<php> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Bagwaa\ReallyFunnyJokes; | ||
|
||
class JokeFactory | ||
{ | ||
/** | ||
* A silo of brilliant jokes, non are stale here | ||
* | ||
* @var array | ||
*/ | ||
protected $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 - The Madness Starts Here! | ||
* | ||
* @param array $jokes | ||
*/ | ||
public function __construct(array $jokes = null) | ||
{ | ||
if ($jokes) { | ||
$this->jokes = $jokes; | ||
} | ||
} | ||
|
||
/** | ||
* Return a random joke to the caller. | ||
*/ | ||
public function getRandomJoke(): string | ||
{ | ||
return $this->jokes[array_rand($this->jokes)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Bagwaa\ReallyFunnyJokes\Tests; | ||
|
||
use Bagwaa\ReallyFunnyJokes\JokeFactory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class JokeFactoryTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function itReturnsARandomJoke() | ||
{ | ||
$jokes = new JokeFactory([ | ||
'This is a joke', | ||
]); | ||
$joke = $jokes->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); | ||
} | ||
} |