PHP code example of jimdelois / context-specification
1. Go to this page and download the library: Download jimdelois/context-specification library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jimdelois / context-specification example snippets
use ContextSpecification\Framework\Concern;
class When_attempting_to_do_something_awesome_given_a_specific_context extends Concern {
protected function context( ) { ... } // Fill this in!
protected function because( ) { ... } // Fill this in!
/**
* @test
*/
public function should_really_be_awesome( ) {
$awesome = true;
$this->assertTrue( $awesome );
}
/**
* @test
*/
public function then_it_should_not_be_boring( ) {
$boring = false;
$this->assertFalse( $boring );
}
}
use ContextSpecification\Framework\Concern;
use My\Library\AppService\MyAwesomeAppService;
use My\Library\Domain\Awesomeness;
use Phake;
class When_loading_first_awesomeness_from_service_for_date extends Concern {
protected $dao_awesomeness;
protected $date_time;
// Establish a context in which we'll be testing our functionality
protected function context( ) {
$this->date_time = new \DateTime( );
$this->result_expected = new Awesomeness( 'Today will be AWESOME. Maybe.' );
$dao_return_array = array(
$this->result_expected ,
new Awesomeness( 'Should not be seeing this message' ) ,
new Awesomeness( 'Three is a charm' )
);
$this->dao_awesomeness = Phake::mock( 'My\Library\DAO\AwesomenessInterface' );
Phake::when( $this->dao_awesomeness )->loadAllByDate( $this->date_time )->thenReturn( $dao_return_array );
}
// Setup a System-Under-Test
protected function createSUT( ) {
return new MyAwesomeAppService( $this->dao_awesomeness );
}
// Execute the functionality; the "state change."
protected function because( ) {
$this->result_actual = $this->sut->getFirstAvailableAwesomenessForDate( $this->date_time );
}
/**
* @test
*/
public function should_call_appropriate_method_on_awesomeness_dao( ) {
Phake::verify( $this->dao_awesomeness )->loadAllByDate( $this->date_time );
Phake::verifyNoFurtherInteraction( $this->dao_awesomeness );
}
/**
* @test
*/
public function should_return_correct_awesomeness_object( ) {
$this->assertEquals( $this->result_expected , $this->result_actual );
}
}
use ContextSpecification\Framework\Concern;
use My\Library\AppService\MyAwesomeAppService;
use My\Library\Domain\Awesomeness;
use Phake;
class When_loading_first_awesomeness_from_service_for_non_date_input extends Concern {
protected $dao_awesomeness;
protected $date_time_invalid;
// Establish a context in which we'll be testing our functionality
protected function context( ) {
// This causes the library to trap the contents of "because" into a lambda for later execution.
$this->becauseWillThrowException( );
$this->date_time_invalid = 'THIS_IS_A_STRING';
$this->dao_awesomeness = Phake::mock( 'My\Library\DAO\AwesomenessInterface' );
}
// Setup a System-Under-Test
protected function createSUT( ) {
return new MyAwesomeAppService( $this->dao_awesomeness );
}
// Execute the functionality; the "state change."
protected function because( ) {
$this->sut->getFirstAvailableAwesomenessForDate( $this->date_time_invalid );
}
/**
* @test
*/
public function should_raise_invalid_argument_exception( ) {
$this->setExpectedException( '\InvalidArgumentException' );
$this->releaseException( );
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.