|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\Http; |
|
4
|
|
|
|
|
5
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\HttpTransaction; |
|
6
|
|
|
use Loevgaard\DandomainAltapayBundle\Http\TransactionLogger; |
|
7
|
|
|
use Loevgaard\DandomainAltapayBundle\Manager\HttpTransactionManager; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
final class TransactionLoggerTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testTransactionLog() |
|
15
|
|
|
{ |
|
16
|
|
|
$request = new Request(); |
|
17
|
|
|
$response = new Response(); |
|
18
|
|
|
|
|
19
|
|
|
/** @var HttpTransactionManager|\PHPUnit_Framework_MockObject_MockObject $httpTransactionManager */ |
|
20
|
|
|
$httpTransactionManager = $this->getMockBuilder(HttpTransactionManager::class) |
|
21
|
|
|
->disableOriginalConstructor() |
|
22
|
|
|
->getMock() |
|
23
|
|
|
; |
|
24
|
|
|
|
|
25
|
|
|
$httpTransactionManager |
|
|
|
|
|
|
26
|
|
|
->expects($this->any()) |
|
27
|
|
|
->method('create') |
|
28
|
|
|
->willReturnCallback([$this, 'createHttpTransaction']) |
|
29
|
|
|
; |
|
30
|
|
|
|
|
31
|
|
|
$transactionCounter = 0; |
|
32
|
|
|
|
|
33
|
|
|
$httpTransactionManager |
|
34
|
|
|
->expects($this->any()) |
|
35
|
|
|
->method('update') |
|
36
|
|
|
->willReturnCallback(function ($entity) use ($request, $response, &$transactionCounter) { |
|
|
|
|
|
|
37
|
|
|
/* @var HttpTransaction $entity */ |
|
38
|
|
|
++$transactionCounter; |
|
39
|
|
|
}) |
|
40
|
|
|
; |
|
41
|
|
|
|
|
42
|
|
|
$transactionLogger = new TransactionLogger($httpTransactionManager); |
|
43
|
|
|
$transactionLogger->setRequest($request); |
|
44
|
|
|
$transactionLogger->setResponse($request, $response); |
|
45
|
|
|
$transactionLogger->flush(); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertSame(1, $transactionCounter); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return HttpTransaction|\PHPUnit_Framework_MockObject_MockObject |
|
52
|
|
|
*/ |
|
53
|
|
|
public function createHttpTransaction() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getMockForAbstractClass(HttpTransaction::class); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: