SlideShare uma empresa Scribd logo
1 de 1
Baixar para ler offline
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)

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

An ACE in the Hole - Stealthy Host Persistence via Security Descriptors
An ACE in the Hole - Stealthy Host Persistence via Security DescriptorsAn ACE in the Hole - Stealthy Host Persistence via Security Descriptors
An ACE in the Hole - Stealthy Host Persistence via Security Descriptors
 
Secured API Acceleration with Engineers from Amazon CloudFront and Slack
Secured API Acceleration with Engineers from Amazon CloudFront and SlackSecured API Acceleration with Engineers from Amazon CloudFront and Slack
Secured API Acceleration with Engineers from Amazon CloudFront and Slack
 
5조_최종발표.pptx
5조_최종발표.pptx5조_최종발표.pptx
5조_최종발표.pptx
 
Building Pluggable Web Applications using Django
Building Pluggable Web Applications using DjangoBuilding Pluggable Web Applications using Django
Building Pluggable Web Applications using Django
 
DCSF 19 Accelerating Docker Containers with NVIDIA GPUs
DCSF 19 Accelerating Docker Containers with NVIDIA GPUsDCSF 19 Accelerating Docker Containers with NVIDIA GPUs
DCSF 19 Accelerating Docker Containers with NVIDIA GPUs
 
ここまできた! Google Cloud Platform Virtual Private Cloud 徹底解説
ここまできた! Google Cloud Platform Virtual Private Cloud 徹底解説ここまできた! Google Cloud Platform Virtual Private Cloud 徹底解説
ここまできた! Google Cloud Platform Virtual Private Cloud 徹底解説
 
[122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기
[122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기 [122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기
[122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기
 
AWS運用における最適パターンの徹底活用
AWS運用における最適パターンの徹底活用AWS運用における最適パターンの徹底活用
AWS運用における最適パターンの徹底活用
 
ASP.NET SPA開発をはじめよう~今と未来とステップアップ
ASP.NET SPA開発をはじめよう~今と未来とステップアップASP.NET SPA開発をはじめよう~今と未来とステップアップ
ASP.NET SPA開発をはじめよう~今と未来とステップアップ
 
AWS 에서 DevOps 시작하기 – 정영준, AWS 솔루션즈 아키텍트:: AWS Builders Online Series
AWS 에서 DevOps 시작하기 – 정영준, AWS 솔루션즈 아키텍트:: AWS Builders Online Series AWS 에서 DevOps 시작하기 – 정영준, AWS 솔루션즈 아키텍트:: AWS Builders Online Series
AWS 에서 DevOps 시작하기 – 정영준, AWS 솔루션즈 아키텍트:: AWS Builders Online Series
 
Building better Node.js applications on MariaDB
Building better Node.js applications on MariaDBBuilding better Node.js applications on MariaDB
Building better Node.js applications on MariaDB
 
K8s, Amazon EKS - 유재석, AWS 솔루션즈 아키텍트
K8s, Amazon EKS - 유재석, AWS 솔루션즈 아키텍트K8s, Amazon EKS - 유재석, AWS 솔루션즈 아키텍트
K8s, Amazon EKS - 유재석, AWS 솔루션즈 아키텍트
 
「落ちない」AWSのインフラ構成、システム要件にあわせたパターンをご紹介
「落ちない」AWSのインフラ構成、システム要件にあわせたパターンをご紹介「落ちない」AWSのインフラ構成、システム要件にあわせたパターンをご紹介
「落ちない」AWSのインフラ構成、システム要件にあわせたパターンをご紹介
 
Let'Swift 2022 PencilKit과 Point in Polygon 알고리즘을 활용한 올가미 툴 개발기
Let'Swift 2022 PencilKit과 Point in Polygon 알고리즘을 활용한 올가미 툴 개발기Let'Swift 2022 PencilKit과 Point in Polygon 알고리즘을 활용한 올가미 툴 개발기
Let'Swift 2022 PencilKit과 Point in Polygon 알고리즘을 활용한 올가미 툴 개발기
 
Amazon Connect ハンズオン初級編
Amazon Connect ハンズオン初級編Amazon Connect ハンズオン初級編
Amazon Connect ハンズオン初級編
 
Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM
 
100.RED HAT SINGLE SIGN-ON
100.RED HAT SINGLE SIGN-ON100.RED HAT SINGLE SIGN-ON
100.RED HAT SINGLE SIGN-ON
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 
A guide to adding the CC BY license notice
A guide to adding the CC BY license noticeA guide to adding the CC BY license notice
A guide to adding the CC BY license notice
 
DevOps 오픈소스 트랜드 (클라우드, 모바일 중심)
DevOps 오픈소스 트랜드 (클라우드, 모바일 중심) DevOps 오픈소스 트랜드 (클라우드, 모바일 중심)
DevOps 오픈소스 트랜드 (클라우드, 모바일 중심)
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

PHPUnit Cheat Sheet

  • 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)