Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunty committed Aug 17, 2017
1 parent 5b69b44 commit d9273ef
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 55 deletions.
10 changes: 5 additions & 5 deletions spec/AsyncCheckerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
use Brunty\Cigar\Url;
use Brunty\Cigar\Result;

describe('AsyncChecker', function() {
it('checks a domain', function() {
describe('AsyncChecker', function () {
it('checks a domain', function () {
$domain = new Url('http://httpbin.org/status/200', 200);
$domains = [$domain];

$results = (new AsyncChecker)->check($domains);

$expected = [
new Result($domain, 200)
new Result($domain, 200),
];

expect($results)->toEqual($expected);
});

it('checks more than one domain', function() {
it('checks more than one domain', function () {

$domains = [
new Url('http://httpbin.org/status/200', 200),
Expand All @@ -28,7 +28,7 @@

$results = (new AsyncChecker)->check($domains);

$expected = array_map(function(Url $domain){
$expected = array_map(function (Url $domain) {
return new Result($domain, $domain->getStatus());
}, $domains);

Expand Down
14 changes: 7 additions & 7 deletions spec/CigarCliSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@

use Symfony\Component\Process\Process;

describe('Cigar CLI Tool', function() {
describe('Cigar CLI Tool', function () {

// this is here to clean up config files from each test
afterEach(function() {
afterEach(function () {
$process = new Process('cd spec && rm .*.json');
$process->run();
});

it('passes if given good URLs to check', function() {
it('passes if given good URLs to check', function () {
$process = new Process('cd spec && cp stubs/.cigar.pass.json .cigar.json && ../bin/cigar');
$process->run();

expect($process->getExitCode())->toBe(0);
});

it('is quiet if given the option', function() {
it('is quiet if given the option', function () {
$process = new Process('cd spec && cp stubs/.cigar.pass.json .cigar.json && ../bin/cigar --quiet');
$process->run();

expect($process->getOutput())->toBe('');
expect($process->getExitCode())->toBe(0);
});

it('fails if given bad URLs to check', function() {
it('fails if given bad URLs to check', function () {
$process = new Process('cd spec && cp stubs/.cigar.fail.json .cigar.json && ../bin/cigar');
$process->run();

expect($process->getExitCode())->toBe(1);
});

it('can be given an alternative configuration file to load with a short command line flag', function() {
it('can be given an alternative configuration file to load with a short command line flag', function () {
$process = new Process('cd spec && cp stubs/.cigar.pass.json .config.json && ../bin/cigar -c .config.json');
$process->run();

expect($process->getExitCode())->toBe(0);
});

it('can be given an alternative configuration file to load with a long command line flag', function() {
it('can be given an alternative configuration file to load with a long command line flag', function () {
$process = new Process('cd spec && cp stubs/.cigar.pass.json .config.json && ../bin/cigar --config .config.json');
$process->run();

Expand Down
47 changes: 16 additions & 31 deletions spec/OutputterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
use Brunty\Cigar\Outputter;

describe('Outputter', function () {
beforeEach(function() {
$this->domain = new \Brunty\Cigar\Url('url', 418, 'teapot');
$this->results = [
new \Brunty\Cigar\Result($this->domain, 418, 'teapot'),
new \Brunty\Cigar\Result($this->domain, 419),
];
});

it('outputs an error line', function () {
$fn = function () {
(new Outputter)->writeErrorLine('Error message');
Expand All @@ -20,11 +28,7 @@
});

it('outputs results', function () {
$domain = new \Brunty\Cigar\Url('url', 418, 'teapot');
$results = [
new \Brunty\Cigar\Result($domain, 418, 'teapot'),
new \Brunty\Cigar\Result($domain, 419),
];
$results = $this->results;

$fn = function () use ($results) {
(new Outputter)->outputResults($results);
Expand All @@ -40,11 +44,7 @@
});

it('outputs results quietly', function () {
$domain = new \Brunty\Cigar\Url('url', 418, 'teapot');
$results = [
new \Brunty\Cigar\Result($domain, 418, 'teapot'),
new \Brunty\Cigar\Result($domain, 419),
];
$results = $this->results;

$fn = function () use ($results) {
(new Outputter(true))->outputResults($results);
Expand All @@ -54,32 +54,21 @@
});

it('outputs the stats of the execution if all results have passed', function () {
$domain = new \Brunty\Cigar\Url('url', 418, 'teapot');
$results = [
new \Brunty\Cigar\Result($domain, 418, 'teapot'),
new \Brunty\Cigar\Result($domain, 419),
];
$passedResults = $results;
$results = $passedResults = $this->results;

allow('microtime')->toBeCalled()->andReturn(2.5);

$fn = function () use ($results, $passedResults) {
(new Outputter)->outputStats($passedResults, $results, 1.0);
};

$output = PHP_EOL . "[\033[32m2/2\033[0m] passed in 1.5s" . PHP_EOL . PHP_EOL;

expect($fn)->toEcho($output);
expect($fn)->toEcho(PHP_EOL . "[\033[32m2/2\033[0m] passed in 1.5s" . PHP_EOL . PHP_EOL);
});

it('outputs the stats of the execution if some URLs have failed', function () {
$domain = new \Brunty\Cigar\Url('url', 418, 'teapot');
$results = [
new \Brunty\Cigar\Result($domain, 418, 'teapot'),
new \Brunty\Cigar\Result($domain, 419),
];
$results = $this->results;
$passedResults = [
new \Brunty\Cigar\Result($domain, 418, 'teapot'),
new \Brunty\Cigar\Result($this->domain, 418, 'teapot'),
];

allow('microtime')->toBeCalled()->andReturn(2.5);
Expand All @@ -95,13 +84,9 @@


it('does not output stats when run quietly', function () {
$domain = new \Brunty\Cigar\Url('url', 418, 'teapot');
$results = [
new \Brunty\Cigar\Result($domain, 418, 'teapot'),
new \Brunty\Cigar\Result($domain, 419),
];
$results = $this->results;
$passedResults = [
new \Brunty\Cigar\Result($domain, 418, 'teapot'),
new \Brunty\Cigar\Result($this->domain, 418, 'teapot'),
];

allow('microtime')->toBeCalled()->andReturn(2.5);
Expand Down
12 changes: 6 additions & 6 deletions spec/ParserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use Brunty\Cigar\Parser;
use org\bovigo\vfs\vfsStream;

describe('Parser', function() {
it('parses a file that is correctly formatted', function() {
describe('Parser', function () {
it('parses a file that is correctly formatted', function () {
$structure = [
'.cigar.json' => '[
{
Expand All @@ -22,7 +22,7 @@
"content": "teapot"
}
]
'
',
];
vfsStream::setup('root', null, $structure);

Expand All @@ -37,13 +37,13 @@
expect($results)->toEqual($expected);
});

it('lets errors be thrown on parsing a file', function() {
it('lets errors be thrown on parsing a file', function () {
$structure = [
'.cigar.json' => 'http://httpbin.org/status/418'
'.cigar.json' => 'http://httpbin.org/status/418',
];
vfsStream::setup('root', null, $structure);

$fn = function() {
$fn = function () {
(new Parser)->parse('vfs://root/.cigar.json');
};

Expand Down
12 changes: 6 additions & 6 deletions spec/ResultsSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@
use Brunty\Cigar\Url;
use Brunty\Cigar\Result;

describe('Result', function() {
it('passes if status codes match', function() {
describe('Result', function () {
it('passes if status codes match', function () {
$domain = new Url('http://httpbin.org/status/200', 200);
$result = new Result($domain, 200);

expect($result->hasPassed())->toBe(true);
});

it('fails if status codes do not match', function() {
it('fails if status codes do not match', function () {
$domain = new Url('http://httpbin.org/status/200', 200);
$result = new Result($domain, 201);

expect($result->hasPassed())->toBe(false);
});

it('passes if the response contains matching content', function() {
it('passes if the response contains matching content', function () {
$domain = new Url('http://httpbin.org/status/200', 200, 'foobar');
$result = new Result($domain, 200, '<h1>foobar</h1>');
expect($result->hasPassed())->toBe(true);
});

it('fails if the response does not contain matching content', function() {
it('fails if the response does not contain matching content', function () {
$domain = new Url('http://httpbin.org/status/200', 200, 'foobar');
$result = new Result($domain, 200, '<h1>hi there</h1>');
expect($result->hasPassed())->toBe(false);
});

it('returns the domain and status code', function() {
it('returns the domain and status code', function () {
$domain = new Url('http://httpbin.org/status/200', 200, 'foobar');
$result = new Result($domain, 200, '<h1>hi there</h1>');

Expand Down

0 comments on commit d9273ef

Please sign in to comment.