Skip to content

Commit 339138c

Browse files
Initial commit
0 parents  commit 339138c

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
vendor
3+
composer.lock

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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;}}}

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

phpunit.xml.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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>

src/JokeFactory.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
?>

tests/JokeFactoryTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)