public function test_create_write orderCopywriterMock this- getMock Or

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
public function test_create_write()
{
$orderCopywriterMock = $this->getMock('OrderCopywriter', ['save']);
$orderCopywriterMock
->expects($this->once())->method('save')
->will($this->returnCallback(function() use ($orderCopywriterMock) {$orderCopywriterMock->id = 'mock_order_copywriter_id'; return true; }));
$orderCopywriterPriceMock = $this->getMock('OrderPlannedPrice', ['mock_getOrderCopywriterPrice']);
$orderCopywriterPriceMock
->expects($this->once())->method('mock_getOrderCopywriterPrice')
->with($this->equalTo([
'contentLength' => 'mock_max_content_length',
'configTextLength' => 1000,
'configTextPrice' => 200,
]))
->will($this->returnValue(100));
$transactionMock = $this->getMock('Transaction', ['mock_createTransaction']);
$transactionMock
->expects($this->once())->method('mock_createTransaction')
->with(
$this->equalTo([
'type' => Transaction::TYPE_COPYWRITER_ORDER,
'status' => Transaction::STATUS_PLANNED,
'order_copywriter_id' => 'mock_order_copywriter_id',
'from_user_id' => 'mock_user_id',
'amount' => 100,
'system_transaction' => 0,
'comment' => 'Оплата за заказ на написание контента #mock_order_copywriter_id',
]))
->will($this->returnValue(true));
$options = [
'user_id' => 'mock_user_id',
'url' => 'mock_url',
'keywords' => 'mock_keywords',
'comment' => 'mock_comment',
'min_content_length' => 'mock_min_content_length',
'max_content_length' => 'mock_max_content_length',
'type' => OrderCopywriter::TYPE_WRITE,
];
BaseDI::$mockClasses = [
'OrderPlannedPrice::getOrderCopywriterPrice' => $orderCopywriterPriceMock,
'Transaction::createTransaction' => $transactionMock,
];
BaseDI::$mockNewClasses = [
'OrderCopywriter' => $orderCopywriterMock,
];
$this->assertNotNull(OrderCopywriter::createCopywriterOrder($options));
}