Skip to content

Instantly share code, notes, and snippets.

@dnaber-de
Last active August 29, 2015 14:24
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 dnaber-de/b3fcda263ae319042e73 to your computer and use it in GitHub Desktop.
Save dnaber-de/b3fcda263ae319042e73 to your computer and use it in GitHub Desktop.
Some example on a simple PHPUnit Mock. Meant as answer to this question: https://twitter.com/Rarst/status/618880034145718272
<?php
class ReleaseTest \PHPUnit_Framework_TestCase {
public function testConstructor() {
$splFileInfoMock = $this->getMockBuilder( 'SplFileInfo' )
->disableOriginalConstructor()
->getMock();
//define the behaviour of the mock
$splFileInfoMock->expects( $this->any() )
->method( 'getRelativePath' )
->willReturn( 'your/testing/path' );
$testee = new Rarst\ReleaseBelt\Release( $splFileMock );
// now test the public properties with assertions.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment