Completed
Push — master ( 5018c3...5108e7 )
by GBProd
07:07
created

DataProviderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRunExecutePopulate() 0 11 1
A getClient() 0 8 1
B testIndexWithIndexAndType() 0 33 1
1
<?php
2
3
namespace Tests\GBProd\ElasticsearchDataProviderBundle\DataProvider;
4
5
use Elasticsearch\Client;
6
use GBProd\ElasticsearchDataProviderBundle\DataProvider\DataProvider;
7
8
/**
9
 * Tests for abstract data provider
10
 * 
11
 * @author gbprod <[email protected]>
12
 */
13
class DataProviderTest extends \PHPUnit_Framework_TestCase
14
{
15
   public function testRunExecutePopulate()
16
   {
17
      $provider = $this->getMockForAbstractClass(DataProvider::class);
18
      
19
      $provider
20
         ->expects($this->once())
21
         ->method('populate')
22
      ;
23
      
24
      $provider->run($this->getClient(), 'index', 'type');
25
   }
26
   
27
   private function getClient()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
28
   {
29
      return $this
30
         ->getMockBuilder(Client::class)
31
         ->disableOriginalConstructor()
32
         ->getMock()
33
      ;
34
   }
35
   
36
   public function testIndexWithIndexAndType()
37
   {
38
      $provider = $this->getMockForAbstractClass(DataProvider::class);
39
      
40
      $client = $this->getClient();
41
      $client
42
         ->expects($this->once())
43
         ->method('index')
44
         ->with([
45
            'index' => 'my_index',
46
            'type'  => 'my_type',
47
            'id'    => 'my_id',
48
            'body'  => ['foo' => 'bar'],
49
         ])
50
      ;
51
      
52
      $provider
53
         ->expects($this->once())
54
         ->method('populate')
55
         ->will(
56
            $this->returnCallback(
57
               function () use ($provider) {
58
                  $provider->index(
59
                     'my_id', 
60
                     ['foo' => 'bar']
61
                  );   
62
               }
63
            )
64
         )
65
      ;
66
      
67
      $provider->run($client, 'my_index', 'my_type');
68
   }
69
}