This repository has been archived by the owner on Feb 22, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 20
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 d23978f
Showing
14 changed files
with
752 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,4 @@ | ||
vendor/ | ||
bin/ | ||
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,14 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar update | ||
|
||
script: | ||
- bin/phpspec r -v | ||
- bin/behat -v |
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,22 @@ | ||
Copyright (c) 2014 Michal Dabrowski, Norbert Orzechowicz | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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,108 @@ | ||
#PhpSpec data provider extension | ||
|
||
This extension allows you to create data providers for examples in specs. | ||
|
||
> At the moment this extension is just a proof of concept, use it at own risk. | ||
## Installation | ||
|
||
``` | ||
require: { | ||
"coduo/phpspec-data-provider-extension": "dev-master" | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Enable exntesion in phpspec.yml file | ||
|
||
``` | ||
extensions: | ||
- Coduo\PhpSpec\DataProviderExtension | ||
``` | ||
|
||
Write a spec: | ||
|
||
```php | ||
<?php | ||
|
||
namespace spec\Coduo\ToString; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
class StringSpec extends ObjectBehavior | ||
{ | ||
/** | ||
* @dataProvider positiveConversionExamples | ||
*/ | ||
function it_convert_input_value_into_string($inputValue, $expectedValue) | ||
{ | ||
$this->beConstructedWith($inputValue); | ||
$this->__toString()->shouldReturn($expectedValue); | ||
} | ||
|
||
public function positiveConversionExamples() | ||
{ | ||
return array( | ||
array(1, '1'), | ||
array(1.1, '1.1'), | ||
array(new \DateTime, '\DateTime'), | ||
array(array('foo', 'bar'), 'Array(2)') | ||
); | ||
} | ||
} | ||
``` | ||
|
||
Write class for spec: | ||
|
||
```php | ||
<?php | ||
|
||
namespace Coduo\ToString; | ||
|
||
class String | ||
{ | ||
private $value; | ||
|
||
public function __construct($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$type = gettype($this->value); | ||
switch ($type) { | ||
case 'array': | ||
return sprintf('Array(%d)', count($this->value)); | ||
case 'object': | ||
return sprintf("\\%s", get_class($this->value)); | ||
default: | ||
return (string) $this->value; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Run php spec | ||
|
||
``` | ||
$ console bin/phpspec run -f pretty | ||
``` | ||
|
||
You should get following output: | ||
|
||
``` | ||
Coduo\ToString\String | ||
12 ✔ convert input value into string | ||
12 ✔ 1) it convert input value into string | ||
12 ✔ 2) it convert input value into string | ||
12 ✔ 3) it convert input value into string | ||
12 ✔ 4) it convert input value into string | ||
1 specs | ||
5 examples (5 passed) | ||
13ms | ||
``` |
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,36 @@ | ||
{ | ||
"name": "coduo/phpspec-data-provider-extension", | ||
"type": "library", | ||
"keywords": ["phpspec", "dataprovider", "extension", "coduo", "data", "provider"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Norbert Orzechowicz", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Michał Dąbrowski", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0", | ||
"phpspec/phpspec": "2.0.*" | ||
}, | ||
"require-dev": { | ||
"behat/behat": "2.4.*@stable", | ||
"symfony/filesystem": "~2.3", | ||
"bossa/phpspec2-expect": "dev-master" | ||
}, | ||
"autoload": { | ||
"psr-0": { "": "src/"} | ||
}, | ||
"config": { | ||
"bin-dir": "bin" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
} | ||
} |
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,126 @@ | ||
<?php | ||
|
||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Input\StringInput; | ||
use Symfony\Component\Console\Output\StreamOutput; | ||
|
||
/** | ||
* A console application tester heavily inspired by/proudly stolen from \Symfony\Component\Console\Tester\ApplicationTester. | ||
*/ | ||
class ApplicationTester | ||
{ | ||
/** | ||
* @var Application $application | ||
*/ | ||
private $application; | ||
|
||
/** | ||
* @var StringInput $input | ||
*/ | ||
private $input; | ||
|
||
/** | ||
* @var StreamOutput $output | ||
*/ | ||
private $output; | ||
|
||
/** | ||
* @var resource $inputStream | ||
*/ | ||
private $inputStream; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $result; | ||
|
||
/** | ||
* @param Application $application | ||
*/ | ||
public function __construct(Application $application) | ||
{ | ||
$this->application = $application; | ||
} | ||
|
||
/** | ||
* @param string $input | ||
* | ||
* @return integer | ||
*/ | ||
public function run($input) | ||
{ | ||
$this->input = new StringInput($input); | ||
|
||
$this->output = new StreamOutput(fopen('php://memory', 'w', false)); | ||
|
||
$inputStream = $this->getInputStream(); | ||
rewind($inputStream); | ||
$this->application->getHelperSet() | ||
->get('dialog') | ||
->setInputStream($inputStream); | ||
|
||
$this->result = $this->application->run($this->input, $this->output); | ||
} | ||
|
||
/** | ||
* @param boolean | ||
* | ||
* @return string | ||
*/ | ||
public function getDisplay($normalize = false) | ||
{ | ||
rewind($this->output->getStream()); | ||
|
||
$display = stream_get_contents($this->output->getStream()); | ||
|
||
if ($normalize) { | ||
$display = str_replace(PHP_EOL, "\n", $display); | ||
} | ||
|
||
return $display; | ||
} | ||
|
||
/** | ||
* @return InputInterface | ||
*/ | ||
public function getInput() | ||
{ | ||
return $this->input; | ||
} | ||
|
||
/** | ||
* @return OutputInterface | ||
*/ | ||
public function getOutput() | ||
{ | ||
return $this->output; | ||
} | ||
|
||
/** | ||
* @param string $input | ||
*/ | ||
public function putToInputStream($input) | ||
{ | ||
fputs($this->getInputStream(), $input); | ||
} | ||
|
||
/** | ||
* @return resource | ||
*/ | ||
private function getInputStream() | ||
{ | ||
if (null === $this->inputStream) { | ||
$this->inputStream = fopen('php://memory', 'r+', false); | ||
} | ||
|
||
return $this->inputStream; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getResult() | ||
{ | ||
return $this->result; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
use Behat\Behat\Context\BehatContext; | ||
|
||
/** | ||
* Features context. | ||
*/ | ||
class FeatureContext extends BehatContext | ||
{ | ||
/** | ||
* Initializes context. | ||
* Every scenario gets it's own context object. | ||
* | ||
* @param array $parameters context parameters (set them up through behat.yml) | ||
*/ | ||
public function __construct(array $parameters) | ||
{ | ||
$this->useContext('phpspec', new PHPSpecContext()); | ||
} | ||
} |
Oops, something went wrong.