Skip to content

Commit 2f87fd7

Browse files
committed
update
1 parent 0e382f5 commit 2f87fd7

File tree

4,293 files changed

+443846
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,293 files changed

+443846
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Mockery
4+
*
5+
* LICENSE
6+
*
7+
* This source file is subject to the new BSD license that is bundled
8+
* with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://github.com/padraic/mockery/blob/master/LICENSE
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to [email protected] so we can send you a copy immediately.
14+
*
15+
* @category Mockery
16+
* @package Mockery
17+
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
18+
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19+
*/
20+
21+
namespace Mockery\Adapter\Phpunit;
22+
23+
use PHPUnit\Framework\ExpectationFailedException;
24+
use PHPUnit\Framework\Test;
25+
use PHPUnit\Framework\TestCase;
26+
use PHPUnit\Util\Blacklist;
27+
use PHPUnit\Runner\BaseTestRunner;
28+
29+
class TestListenerTrait
30+
{
31+
/**
32+
* endTest is called after each test and checks if \Mockery::close() has
33+
* been called, and will let the test fail if it hasn't.
34+
*
35+
* @param Test $test
36+
* @param float $time
37+
*/
38+
public function endTest(Test $test, $time)
39+
{
40+
if (!$test instanceof TestCase) {
41+
// We need the getTestResultObject and getStatus methods which are
42+
// not part of the interface.
43+
return;
44+
}
45+
46+
if ($test->getStatus() !== BaseTestRunner::STATUS_PASSED) {
47+
// If the test didn't pass there is no guarantee that
48+
// verifyMockObjects and assertPostConditions have been called.
49+
// And even if it did, the point here is to prevent false
50+
// negatives, not to make failing tests fail for more reasons.
51+
return;
52+
}
53+
54+
try {
55+
// The self() call is used as a sentinel. Anything that throws if
56+
// the container is closed already will do.
57+
\Mockery::self();
58+
} catch (\LogicException $_) {
59+
return;
60+
}
61+
62+
$e = new ExpectationFailedException(
63+
\sprintf(
64+
"Mockery's expectations have not been verified. Make sure that \Mockery::close() is called at the end of the test. Consider using %s\MockeryPHPUnitIntegration or extending %s\MockeryTestCase.",
65+
__NAMESPACE__,
66+
__NAMESPACE__
67+
)
68+
);
69+
70+
/** @var \PHPUnit\Framework\TestResult $result */
71+
$result = $test->getTestResultObject();
72+
73+
if ($result !== null) {
74+
$result->addFailure($test, $e, $time);
75+
}
76+
}
77+
78+
public function startTestSuite()
79+
{
80+
if (method_exists(Blacklist::class, 'addDirectory')) {
81+
(new BlackList())->getBlacklistedDirectories();
82+
Blacklist::addDirectory(\dirname((new \ReflectionClass(\Mockery::class))->getFileName()));
83+
} else {
84+
Blacklist::$blacklistedClassNames[\Mockery::class] = 1;
85+
}
86+
}
87+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* Mockery
5+
*
6+
* LICENSE
7+
*
8+
* This source file is subject to the new BSD license that is bundled
9+
* with this package in the file LICENSE.txt.
10+
* It is also available through the world-wide-web at this URL:
11+
* http://github.com/padraic/mockery/blob/master/LICENSE
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to [email protected] so we can send you a copy immediately.
15+
*
16+
* @category Mockery
17+
* @package Mockery
18+
* @copyright Copyright (c) 2017 Dave Marshall https://github.com/davedevelopment
19+
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
20+
*/
21+
22+
namespace Mockery;
23+
24+
use Mockery\Matcher\Closure;
25+
26+
/**
27+
* @internal
28+
*/
29+
class ClosureWrapper
30+
{
31+
private $closure;
32+
33+
public function __construct(\Closure $closure)
34+
{
35+
$this->closure = $closure;
36+
}
37+
38+
public function __invoke()
39+
{
40+
return call_user_func_array($this->closure, func_get_args());
41+
}
42+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
/**
3+
* Mockery
4+
*
5+
* LICENSE
6+
*
7+
* This source file is subject to the new BSD license that is bundled
8+
* with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://github.com/padraic/mockery/blob/master/LICENSE
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to [email protected] so we can send you a copy immediately.
14+
*
15+
* @category Mockery
16+
* @package Mockery
17+
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
18+
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19+
*/
20+
21+
namespace Mockery;
22+
23+
class CompositeExpectation implements ExpectationInterface
24+
{
25+
/**
26+
* Stores an array of all expectations for this composite
27+
*
28+
* @var array
29+
*/
30+
protected $_expectations = array();
31+
32+
/**
33+
* Add an expectation to the composite
34+
*
35+
* @param \Mockery\Expectation|\Mockery\CompositeExpectation $expectation
36+
* @return void
37+
*/
38+
public function add($expectation)
39+
{
40+
$this->_expectations[] = $expectation;
41+
}
42+
43+
/**
44+
* @param mixed ...$args
45+
*/
46+
public function andReturn(...$args)
47+
{
48+
return $this->__call(__FUNCTION__, $args);
49+
}
50+
51+
/**
52+
* Set a return value, or sequential queue of return values
53+
*
54+
* @param mixed ...$args
55+
* @return self
56+
*/
57+
public function andReturns(...$args)
58+
{
59+
return call_user_func_array([$this, 'andReturn'], $args);
60+
}
61+
62+
/**
63+
* Intercept any expectation calls and direct against all expectations
64+
*
65+
* @param string $method
66+
* @param array $args
67+
* @return self
68+
*/
69+
public function __call($method, array $args)
70+
{
71+
foreach ($this->_expectations as $expectation) {
72+
call_user_func_array(array($expectation, $method), $args);
73+
}
74+
return $this;
75+
}
76+
77+
/**
78+
* Return order number of the first expectation
79+
*
80+
* @return int
81+
*/
82+
public function getOrderNumber()
83+
{
84+
reset($this->_expectations);
85+
$first = current($this->_expectations);
86+
return $first->getOrderNumber();
87+
}
88+
89+
/**
90+
* Return the parent mock of the first expectation
91+
*
92+
* @return \Mockery\MockInterface|\Mockery\LegacyMockInterface
93+
*/
94+
public function getMock()
95+
{
96+
reset($this->_expectations);
97+
$first = current($this->_expectations);
98+
return $first->getMock();
99+
}
100+
101+
/**
102+
* Mockery API alias to getMock
103+
*
104+
* @return \Mockery\LegacyMockInterface|\Mockery\MockInterface
105+
*/
106+
public function mock()
107+
{
108+
return $this->getMock();
109+
}
110+
111+
/**
112+
* Starts a new expectation addition on the first mock which is the primary
113+
* target outside of a demeter chain
114+
*
115+
* @param mixed ...$args
116+
* @return \Mockery\Expectation
117+
*/
118+
public function shouldReceive(...$args)
119+
{
120+
reset($this->_expectations);
121+
$first = current($this->_expectations);
122+
return call_user_func_array(array($first->getMock(), 'shouldReceive'), $args);
123+
}
124+
125+
/**
126+
* Starts a new expectation addition on the first mock which is the primary
127+
* target outside of a demeter chain
128+
*
129+
* @param mixed ...$args
130+
* @return \Mockery\Expectation
131+
*/
132+
public function shouldNotReceive(...$args)
133+
{
134+
reset($this->_expectations);
135+
$first = current($this->_expectations);
136+
return call_user_func_array(array($first->getMock(), 'shouldNotReceive'), $args);
137+
}
138+
139+
/**
140+
* Return the string summary of this composite expectation
141+
*
142+
* @return string
143+
*/
144+
public function __toString()
145+
{
146+
$return = '[';
147+
$parts = array();
148+
foreach ($this->_expectations as $exp) {
149+
$parts[] = (string) $exp;
150+
}
151+
$return .= implode(', ', $parts) . ']';
152+
return $return;
153+
}
154+
}

0 commit comments

Comments
 (0)