Your SlideShare is downloading. ×
PHPUnit Cheat Sheet
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

PHPUnit Cheat Sheet

1,404
views

Published on

Cheat Sheet of PHPUnit

Cheat Sheet of PHPUnit

Published in: Technology

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,404
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
40
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHPUNIT CHEAT SHEET VERSION 0.1 BASED ON PHPUNIT 3.6ASSERTIONS MATCHERS for EXPECTS RETURNS for WILL method Arrays and Traversable Objects onConsecutiveCalls methodBasics assertArrayHasKey returnArgument anyassertEmpty assertArrayNotHasKey returnCallback atassertEquals assertContains returnValue atLeastOnceassertFalse assertContainsOnly throwException exactlyassertGreaterThan assertCount neverassertGreaterThanOrEqual assertNotContains once “getMock()” methodassertInternalType assertNotContainsOnly /**assertLessThan assertNotCount CONSTRAINTS for WITH * @return PHPUnit_Framework_assertLessThanOrEqual * MockObject_MockObjectassertNotEmpty 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 = TRUEObjects assertStringMatchesFormat anything )assertInstanceOf assertStringMatchesFormatFile arrayHasKeyassertObjectHasAttribute assertStringNotEqualsFile containsassertObjectNotHasAttribute assertStringNotMatchesFormat equalTo Template methodsassertNotInstanceOf 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 lessThanOrEqualClasses and Objects assertXmlFileEqualsXmlFile UtilitiesassertAttributeContains 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 hasAttributeassertAttributeInstanceOf Files isInstanceOf AnnotationsassertAttributeInternalType assertFileEquals isType /**assertAttributeLessThan assertFileExists String * @expectedException <exceptionName>assertAttributeLessThanOrEqual assertFileNotEquals * @dataProvider <methodName>assertAttributeNotContains assertFileNotExists matchesRegularExpression * @depends <methodName>assertAttributeNotContainsOnly stringContains Others */assertAttributeNotEmpty stringEndsWithassertAttributeNotEquals assertThat stringStartsWith <exceptionName> can be:assertAttributeNotInstanceOf PHPUnit_Framework_ErrorassertAttributeNotInternalType Others PHPUnit_Framework_WarningassertAttributeNotSame fileExistsassertAttributeSameExample 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)