Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
PHPUNIT CHEAT SHEET                                                                    VERSION 0.1 BASED ON PHPUNIT 3.6ASS...
Prochain SlideShare
Chargement dans…5
×

PHPUnit Cheat Sheet

3 507 vues

Publié le

Cheat Sheet of PHPUnit

Publié dans : Technologie
  • Soyez le premier à commenter

PHPUnit Cheat Sheet

  1. 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)

×