Skip to content

Commit

Permalink
Merge pull request #16 from psaintlaurent/master
Browse files Browse the repository at this point in the history
Update phpunit-extensions to use sebastianbergmann/exporter
  • Loading branch information
psaintlaurent committed Oct 20, 2015
2 parents 3dd0339 + f785bf0 commit 7cb1529
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions PHPUnit/Extensions/Constraint/ArrayEqualsNoOrder.php
@@ -1,5 +1,7 @@
<?php

use SebastianBergmann\Exporter\Exporter;

/**
* Determines whether or not the array contains the same exact contents,
* but not necessarily the same order.
Expand All @@ -8,8 +10,11 @@ class PHPUnit_Extensions_Constraint_ArrayEqualsNoOrder
extends PHPUnit_Framework_Constraint_And {

private $andConstraint;
protected $exporter;

public function __construct($expected) {

$this->exporter = new Exporter;
$this->setConstraints(
array(
new PHPUnit_Extensions_Constraint_HasItems($expected),
Expand Down
8 changes: 6 additions & 2 deletions PHPUnit/Extensions/Constraint/ArrayHasKeyValuePair.php
@@ -1,5 +1,7 @@
<?php

use SebastianBergmann\Exporter\Exporter;

/**
* Constraint that asserts that the array it is evaluated for has a given key
* and value combination.
Expand All @@ -15,6 +17,7 @@ class PHPUnit_Extensions_Constraint_ArrayHasKeyValuePair extends PHPUnit_Framewo
*/
protected $value;

protected $exporter;
/**
* @param integer|string $key
* @param mixed $value
Expand All @@ -23,6 +26,7 @@ public function __construct($key, $value)
{
$this->key = $key;
$this->value = $value;
$this->exporter = new Exporter;
}

/**
Expand All @@ -47,8 +51,8 @@ protected function matches($other)
*/
public function toString()
{
return 'has the key ' . PHPUnit_Util_Type::export($this->key) .
' with the value ' . PHPUnit_Util_Type::export($this->value);
return 'has the key ' . $this->exporter->export($this->key) .
' with the value ' . $this->exporter->export($this->value);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions PHPUnit/Extensions/Constraint/EqualsClosure.php
@@ -1,14 +1,17 @@
<?php
use SebastianBergmann\Exporter\Exporter;

class PHPUnit_Extensions_Constraint_EqualsClosure
extends PHPUnit_Framework_Constraint {

private $expected;
private $closure;
protected $exporter;

public function __construct($expected, $closure) {
$this->expected = $expected;
$this->closure = $closure;
$this->exporter = new Exporter;
}

protected function matches($actual) {
Expand All @@ -20,7 +23,7 @@ protected function matches($actual) {

public function toString() {
return sprintf('is equal to %s',
PHPUnit_Util_Type::export($this->expected)
$this->exporter->export($this->expected)
);
}
}
}
6 changes: 5 additions & 1 deletion PHPUnit/Extensions/Constraint/HasItems.php
@@ -1,15 +1,19 @@
<?php

use SebastianBergmann\Exporter\Exporter;

/**
* Determines whether or not the array contains the expected items.
*/
class PHPUnit_Extensions_Constraint_HasItems
extends PHPUnit_Framework_Constraint {

private $expected;
protected $exporter;

public function __construct($expected) {
$this->expected = $expected;
$this->exporter = new Exporter;
}

protected function matches($other) {
Expand All @@ -28,7 +32,7 @@ protected function matches($other) {

public function toString() {
return sprintf('has items %s',
PHPUnit_Util_Type::export($this->expected));
$this->exporter->export($this->expected));
}
}

@@ -1,15 +1,19 @@
<?php

use SebastianBergmann\Exporter\Exporter;

/**
* Constraint for comparing strings while considering all whitespace to be equal.
*/
class PHPUnit_Extensions_Constraint_StringMatchIgnoreWhitespace
extends PHPUnit_Framework_Constraint {

private $expected;
protected $exporter;

public function __construct($expected) {
$this->expected = $expected;
$this->exporter = new Exporter;
}

protected function matches($actual) {
Expand All @@ -23,7 +27,7 @@ private function normalize($string) {
public function toString() {
return sprintf(
'equals ignoring whitespace %s',
PHPUnit_Util_Type::export($this->normalize($this->expected)));
$this->exporter->export($this->normalize($this->expected)));
}
}

8 changes: 6 additions & 2 deletions PHPUnit/Extensions/MockObject/Stub/ReturnMapping.php
@@ -1,11 +1,13 @@
<?php

use SebastianBergmann\Exporter\Exporter;

class PHPUnit_Extensions_MockObject_Stub_ReturnMapping
implements PHPUnit_Framework_MockObject_Stub {

protected $return_map;
protected $default;

protected $exporter;
/**
* @param array $return_map an array of
* PHPUnit_Extensions_Mock_Object_Stub_ReturnMapping_Entry.
Expand All @@ -19,13 +21,15 @@ public function __construct(
) {
$this->return_map = $return_map;
$this->default = $default;
$this->exporter = new Exporter;
}

/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return the invocation of the Entry with matching parameters.
*/
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) {

foreach ($this->return_map as $entry) {
if ($entry->matches($invocation)) {
return $entry->invoke($invocation);
Expand All @@ -39,7 +43,7 @@ public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) {
PHPUnit_Framework_Assert::fail(
sprintf(
'No return value defined for %s',
PHPUnit_Util_Type::export($invocation->parameters)));
$this->exporter->export($invocation->parameters)));
}

public function toString() {
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -12,6 +12,7 @@
"require": {
"php": ">=5.3.6",
"phpunit/PHPUnit": ">=3.6.10",
"sebastian/exporter": "1.0.*",
"mockery/mockery": "0.8.0"
},
"autoload": {
Expand Down

0 comments on commit 7cb1529

Please sign in to comment.