Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
PHPUNIT CHEAT SHEET
                                                                    VERSION 0.1 BASED ON PHPUNIT 3.6

...
Upcoming SlideShare
Loading in …5
×
Upcoming SlideShare
Legal analysis of source code
Next
Download to read offline and view in fullscreen.

7

Share

PHPUnit Cheat Sheet

Download to read offline

Cheat Sheet of PHPUnit

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

PHPUnit Cheat Sheet

  1. 1. PHPUNIT CHEAT SHEET VERSION 0.1 BASED ON PHPUNIT 3.6 ASSERTIONS MATCHERS for EXPECTS RETURNS for WILL method Arrays and Traversable Objects onConsecutiveCalls method Basics assertArrayHasKey returnArgument any assertEmpty assertArrayNotHasKey returnCallback at assertEquals assertContains returnValue atLeastOnce assertFalse assertContainsOnly throwException exactly assertGreaterThan assertCount never assertGreaterThanOrEqual assertNotContains once “getMock()” method assertInternalType assertNotContainsOnly /** assertLessThan assertNotCount CONSTRAINTS for WITH * @return PHPUnit_Framework_ assertLessThanOrEqual * MockObject_MockObject assertNotEmpty Strings method */ assertNotEquals assertNotRegExp Commutation public function getMock( assertNotInternalType assertRegExp $originalClassName, assertNotNull assertSelectEquals logicalAnd $methods = array(), assertNotSame assertSelectCount logicalNot array $arguments = array(), assertNull assertSelectRegExp logicalOr $mockClassName = '', assertSame assertStringEndsNotWith logicalXor $callOriginalConstructor = TRUE, assertTrue assertStringEndsWith Basics $callOriginalClone = TRUE, assertStringEqualsFile $callAutoload = TRUE Objects assertStringMatchesFormat anything ) assertInstanceOf assertStringMatchesFormatFile arrayHasKey assertObjectHasAttribute assertStringNotEqualsFile contains assertObjectNotHasAttribute assertStringNotMatchesFormat equalTo Template methods assertNotInstanceOf assertStringNotMatchesFormatFile greaterThan pub static fn setUpBeforeClass() assertStringStartsNotWith greaterThanOrEqual pro fn setUp() Classes assertStringStartsWith identicalTo pro fn assertPreConditions() assertClassHasAttribute isFalse pro fn assertPostConditions() assertClassHasStaticAttribute XML and HTML isNull pro fn tearDown() assertClassNotHasAttribute assertEqualXMLStructure isTrue pub static fn tearDownAfterClass() assertClassNotHasStaticAttribute assertNotTag lessThan pro fn onNotSuccessfulTest() assertTag lessThanOrEqual Classes and Objects assertXmlFileEqualsXmlFile Utilities assertAttributeContains assertXmlFileNotEqualsXmlFile Classes & Objects $this->fail() assertAttributeContainsOnly assertXmlStringEqualsXmlFile attribute $this->markTestIncomplete() assertAttributeEmpty assertXmlStringEqualsXmlString attributeEqualTo $this->markTestSkipped() assertAttributeEquals assertXmlStringNotEqualsXmlFile classHasAttribute $this->expectOutputString() assertAttributeGreaterThan assertXmlStringNotEqualsXmlString classHasStaticAttribute $this->setExpectedException() assertAttributeGreaterThanOrEqual hasAttribute assertAttributeInstanceOf Files isInstanceOf Annotations assertAttributeInternalType assertFileEquals isType /** assertAttributeLessThan assertFileExists String * @expectedException <exceptionName> assertAttributeLessThanOrEqual assertFileNotEquals * @dataProvider <methodName> assertAttributeNotContains assertFileNotExists matchesRegularExpression * @depends <methodName> assertAttributeNotContainsOnly stringContains Others */ assertAttributeNotEmpty stringEndsWith assertAttributeNotEquals assertThat stringStartsWith <exceptionName> can be: assertAttributeNotInstanceOf PHPUnit_Framework_Error assertAttributeNotInternalType Others PHPUnit_Framework_Warning assertAttributeNotSame fileExists assertAttributeSame Example with a Mock object Testing Exceptions <?php /** require_once 'SomeClass.php'; * @expectedException MyException */ class StubTest extends PHPUnit_Framework_TestCase public function testThrowsAnException() { { public function testStub() $stub = $this->getMock(‘stdClass’); { $stub->expects( $this->any() ) // Create a stub for the SomeClass class ->method(‘push’) $stub = $this->getMock('SomeClass', array(‘doSomething’) ); ->will( $this->throwException( new MyException ) ); $stub->push(42); // Configure the stub } $stub->expects( $this->once() ) ->method( 'doSomething' ) ->with( $this->equalTo('bar') ) ->will( $this->returnValue('foo') ); // Calling $stub->doSomething() will now return 'foo' $this->assertEquals('foo', $stub->doSomething('bar')); } } “PHPUnit Cheat Sheet” by Ian Monge (http://otroblogmas.com) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
  • MichaGoza

    Jan. 12, 2017
  • sokphea_chea

    Jun. 29, 2016
  • TravisJones15

    Mar. 15, 2016
  • doutdex

    Feb. 9, 2015
  • r00vi

    Jun. 14, 2013
  • gabymolinagoigoux

    Oct. 29, 2012
  • ianmonge

    Jun. 2, 2011

Cheat Sheet of PHPUnit

Views

Total views

3,791

On Slideshare

0

From embeds

0

Number of embeds

92

Actions

Downloads

69

Shares

0

Comments

0

Likes

7

×