| 148 |
lars |
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 padraic@php.net 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 Mockery;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Integrates Mockery into PHPUnit. Ensures Mockery expectations are verified
|
|
|
27 |
* for each test and are included by the assertion counter.
|
|
|
28 |
*/
|
|
|
29 |
trait MockeryPHPUnitIntegration
|
|
|
30 |
{
|
|
|
31 |
use MockeryPHPUnitIntegrationAssertPostConditions;
|
|
|
32 |
|
|
|
33 |
protected $mockeryOpen;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Performs assertions shared by all tests of a test case. This method is
|
|
|
37 |
* called before execution of a test ends and before the tearDown method.
|
|
|
38 |
*/
|
|
|
39 |
protected function mockeryAssertPostConditions()
|
|
|
40 |
{
|
|
|
41 |
$this->addMockeryExpectationsToAssertionCount();
|
|
|
42 |
$this->checkMockeryExceptions();
|
|
|
43 |
$this->closeMockery();
|
|
|
44 |
|
|
|
45 |
parent::assertPostConditions();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
protected function addMockeryExpectationsToAssertionCount()
|
|
|
49 |
{
|
|
|
50 |
$this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount());
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
protected function checkMockeryExceptions()
|
|
|
54 |
{
|
|
|
55 |
if (!method_exists($this, "markAsRisky")) {
|
|
|
56 |
return;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
foreach (Mockery::getContainer()->mockery_thrownExceptions() as $e) {
|
|
|
60 |
if (!$e->dismissed()) {
|
|
|
61 |
$this->markAsRisky();
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
protected function closeMockery()
|
|
|
67 |
{
|
|
|
68 |
Mockery::close();
|
|
|
69 |
$this->mockeryOpen = false;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* @before
|
|
|
74 |
*/
|
|
|
75 |
protected function startMockery()
|
|
|
76 |
{
|
|
|
77 |
$this->mockeryOpen = true;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* @after
|
|
|
82 |
*/
|
|
|
83 |
protected function purgeMockeryContainer()
|
|
|
84 |
{
|
|
|
85 |
if ($this->mockeryOpen) {
|
|
|
86 |
// post conditions wasn't called, so test probably failed
|
|
|
87 |
Mockery::close();
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|