Permalink
Browse files

PHPUnit integration

  • Loading branch information...
malkusch committed Apr 1, 2015
0 parents commit dbd6e8ba27ba0e00b03255eecb0c11e496e45e67
@@ -0,0 +1,39 @@
language: php
sudo: false
cache:
directories:
- $HOME/.composer/cache
env:
- PHPUNIT_VERSION=dev-master
- PHPUNIT_VERSION=~4.5.0
- PHPUNIT_VERSION=~4.4.0
- PHPUNIT_VERSION=~4.3.0
- PHPUNIT_VERSION=~4.2.0
- PHPUNIT_VERSION=~4.1.0
- PHPUNIT_VERSION=~4.0.0
php:
- 7.0
- 5.6
- 5.5
- 5.4
- hhvm
matrix:
fast_finish: true
allow_failures:
- php: hhvm
install:
- composer require phpunit/phpunit:${PHPUNIT_VERSION}
- composer require squizlabs/php_codesniffer
- composer require phpmd/phpmd
script:
- vendor/bin/phpunit
- vendor/bin/phpcs --standard=PSR2 classes/ tests/
- vendor/bin/phpmd classes/ text cleancode,codesize,controversial,design,naming,unusedcode
14 LICENSE
@@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
@@ -0,0 +1,51 @@
# Mock PHP built-in functions with PHPUnit
This package integrates the function mock library
[PHP-Mock](https://github.com/php-mock/php-mock) with PHPUnit.
# Requirements
# Installation
# Usage
PHP-Mock integrates with the trait
[`PHPMock`](http://php-mock.github.io/phpunit/api/class-phpmock.phpunit.PHPMock.html)
to integrate into your PHPUnit-4 test case. This trait extends the framework
by the method
[`getFunctionMock()`](http://php-mock.github.io/phpunit/api/class-phpmock.phpunit.PHPMock.html#_getFunctionMock).
With this method you can build a mock in the way you are used to build a
PHPUnit mock:
```php
<?php
namespace foo;
use phpmock\phpunit\PHPMock;
class FooTest extends \PHPUnit_Framework_TestCase
{
use PHPMock;
public function testBar()
{
$time = $this->getFunctionMock(__NAMESPACE__, "time");
$time->expects($this->once())->willReturn(3);
$this->assertEquals(3, time());
}
}
```
# License and authors
This project is free and under the WTFPL.
Responsable for this project is Markus Malkusch markus@malkusch.de.
## Donations
If you like this project and feel generous donate a few Bitcoins here:
[1335STSwu9hST4vcMRppEPgENMHD2r1REK](bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK)
[![Build Status](https://travis-ci.org/php-mock/phpunit.svg?branch=master)](https://travis-ci.org/php-mock/phpunit)
@@ -0,0 +1,54 @@
<?php
namespace phpmock\phpunit;
use malkusch\phpmock\MockFunctionHelper;
/**
* Removes default arguments from the invocation.
*
* @author Markus Malkusch <markus@malkusch.de>
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
* @license http://www.wtfpl.net/txt/copying/ WTFPL
* @internal
*/
class DefaultArgumentRemover implements \PHPUnit_Framework_MockObject_Matcher_Invocation
{
/**
* @SuppressWarnings(PHPMD)
*/
public function invoked(\PHPUnit_Framework_MockObject_Invocation $invocation)
{
}
/**
* @SuppressWarnings(PHPMD)
*/
public function matches(\PHPUnit_Framework_MockObject_Invocation $invocation)
{
MockFunctionHelper::removeDefaultArguments($invocation->parameters);
return false;
}
public function verify()
{
}
/**
* This method is not defined in the interface, but used in
* PHPUnit_Framework_MockObject_InvocationMocker::hasMatchers().
*
* @return boolean
* @see \PHPUnit_Framework_MockObject_InvocationMocker::hasMatchers()
*/
public function hasMatchers()
{
return false;
}
public function toString()
{
return __CLASS__;
}
}
@@ -0,0 +1,49 @@
<?php
namespace phpmock\phpunit;
use malkusch\phpmock\Deactivatable;
/**
* Test listener for PHPUnit integration.
*
* This class disables mock functions after a test was run.
*
* @author Markus Malkusch <markus@malkusch.de>
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
* @license http://www.wtfpl.net/txt/copying/ WTFPL
* @internal
*/
class MockDisabler extends \PHPUnit_Framework_BaseTestListener
{
/**
* @var Deactivatable The function mocks.
*/
private $deactivatable;
/**
* Sets the function mocks.
*
* @param Deactivatable $deactivatable The function mocks.
*/
public function __construct(Deactivatable $deactivatable)
{
$this->deactivatable = $deactivatable;
}
/**
* Disables the function mocks.
*
* @param \PHPUnit_Framework_Test $test The test.
* @param int $time The test duration.
*
* @see Mock::disable()
*/
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
parent::endTest($test, $time);
$this->deactivatable->disable();
}
}
@@ -0,0 +1,81 @@
<?php
namespace phpmock\phpunit;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use phpmock\integration\MockDelegateFunctionBuilder;
/**
* Proxy for PHPUnit's PHPUnit_Framework_MockObject_MockObject.
*
* @author Markus Malkusch <markus@malkusch.de>
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
* @license http://www.wtfpl.net/txt/copying/ WTFPL
* @internal
*/
class MockObjectProxy implements MockObject
{
/**
* @var MockObject $mockObject The mock object.
*/
private $mockObject;
/**
* Inject the subject.
*
* @param MockObject $mockObject The subject.
*/
public function __construct(MockObject $mockObject)
{
$this->mockObject = $mockObject;
}
/**
* @SuppressWarnings(PHPMD)
*/
// @codingStandardsIgnoreStart
public function __phpunit_getInvocationMocker()
{
// @codingStandardsIgnoreEnd
return $this->mockObject->__phpunit_getInvocationMocker();
}
/**
* @SuppressWarnings(PHPMD)
*/
// @codingStandardsIgnoreStart
public function __phpunit_setOriginalObject($originalObject)
{
// @codingStandardsIgnoreEnd
return $this->mockObject->__phpunit_setOriginalObject($originalObject);
}
/**
* @SuppressWarnings(PHPMD)
*/
// @codingStandardsIgnoreStart
public function __phpunit_verify()
{
// @codingStandardsIgnoreEnd
return $this->mockObject->__phpunit_verify();
}
public function expects(\PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
{
return $this->mockObject->expects($matcher)->method(MockDelegateFunctionBuilder::METHOD);
}
/**
* This method is not part of the contract but was found in
* PHPUnit's mocked_class.tpl.dist.
*
* @SuppressWarnings(PHPMD)
*/
// @codingStandardsIgnoreStart
public function __phpunit_hasMatchers()
{
// @codingStandardsIgnoreEnd
return $this->mockObject->__phpunit_hasMatchers();
}
}
Oops, something went wrong.

0 comments on commit dbd6e8b

Please sign in to comment.