Skip to content

Instantly share code, notes, and snippets.

@nrocy
Created November 30, 2011 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrocy/1408521 to your computer and use it in GitHub Desktop.
Save nrocy/1408521 to your computer and use it in GitHub Desktop.
PHPSpec Custom Matcher Confusion
<?php
require_once "PHPSpec/Matcher/Functions.php";
// Used http://www.slideshare.net/marcello.duarte/bdd-for-zend-framework-with-php-spec
// Slide 56 as reference.
\PHPSpec\Matcher\define("totallyEqualMan", function($match) {
return array(
"match" => function($actual) use ($match) {
return $actual === $match;
},
"failure_message_for_should" => function($actual) use ($match) {
return "expected {$actual} to be, like, totally equal to {$match}, man";
}
);
});
class DescribeTotallyWorks extends \PHPSpec\Context {
public function itTotallyWorksWhenItShould() {
$this->spec(10)->should->totallyEqualMan(10);
}
public function itTotallyWorksWhenItShouldnt() {
$this->spec(10)->should->totallyEqualMan(11);
}
public function itHasAWorkingPhpSpec() {
$this->spec(10)->should->equal(10);
$this->spec(10)->shouldNot->equal(9);
}
}
/*
$ phpspec --version
1.2.2beta
$ phpspec spec/TotallyWorksSpec.php -f d -c
TotallyWorks
totally works when it should
totally works when it shouldnt <<-- expect this to fail
has a working php spec
Finished in 0.017361 seconds
3 examples
$ pear list -a
Installed packages, channel __uri:
==================================
(no packages installed)
Installed packages, channel doc.php.net:
========================================
(no packages installed)
Installed packages, channel hamcrest.googlecode.com/svn/pear:
=============================================================
Package Version State
Hamcrest 0.3.0 stable
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.8 stable
Console_Getopt 1.3.1 stable
PEAR 1.9.4 stable
Structures_Graph 1.0.4 stable
XML_Util 1.2.1 stable
Installed packages, channel pear.phpspec.net:
=============================================
Package Version State
PHPSpec 1.2.2beta beta
PHPSpec_Mocks 1.1.0beta beta
PHPSpec_Zend 1.2beta beta
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
Text_Template 1.1.1 stable
Installed packages, channel pear.survivethedeepend.com:
=======================================================
Package Version State
Mockery 0.7.1 stable
Installed packages, channel pecl.php.net:
=========================================
(no packages installed)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment