Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
bagwaa committed Feb 11, 2020
0 parents commit c3e88eb
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
build
composer.lock
26 changes: 26 additions & 0 deletions composer.json
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/"
}
}
}
29 changes: 29 additions & 0 deletions phpunit.xml.dist
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>
39 changes: 39 additions & 0 deletions src/JokeFactory.php
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)];
}
}
41 changes: 41 additions & 0 deletions tests/JokeFactoryTest.php
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);
}
}

0 comments on commit c3e88eb

Please sign in to comment.