| Total Complexity | 2 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 6 | class DijkstraWalkerTest extends TestCase |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @expectedException \RuntimeException |
||
| 10 | */ |
||
| 11 | public function testThrownAnExceptionWheneverPathIsRequestedBeforeBuild() |
||
| 12 | { |
||
| 13 | $this->mapper = $this |
||
| 14 | ->getMockBuilder('Mado\QueryBundle\Component\Meta\DataMapper') |
||
| 15 | ->disableOriginalConstructor() |
||
| 16 | ->getMock(); |
||
| 17 | |||
| 18 | $this->dijkstra = $this |
||
| 19 | ->getMockBuilder('Mado\QueryBundle\Component\Meta\Dijkstra') |
||
| 20 | ->disableOriginalConstructor() |
||
| 21 | ->getMock(); |
||
| 22 | |||
| 23 | $this->walker = new DijkstraWalker( |
||
| 24 | $this->mapper, |
||
| 25 | $this->dijkstra |
||
| 26 | ); |
||
| 27 | |||
| 28 | $this->walker->getPath(); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function testBuildPathUsingDijkstra() |
||
| 32 | { |
||
| 33 | $this->mapper = $this |
||
| 34 | ->getMockBuilder('Mado\QueryBundle\Component\Meta\DataMapper') |
||
| 35 | ->disableOriginalConstructor() |
||
| 36 | ->getMock(); |
||
| 37 | $this->mapper->expects($this->once()) |
||
| 38 | ->method('getMap') |
||
| 39 | ->will($this->returnValue($laMappa = [ |
||
| 40 | 'start' => [ |
||
| 41 | 'relations' => [ |
||
| 42 | 'fine' => 'end', |
||
| 43 | ] |
||
| 44 | ], |
||
| 45 | 'end' => [ |
||
| 46 | 'relations' => [ |
||
| 47 | 'inizio' => 'start', |
||
| 48 | ] |
||
| 49 | ] |
||
| 50 | ])); |
||
| 51 | |||
| 52 | $this->dijkstra = $this |
||
| 53 | ->getMockBuilder('Mado\QueryBundle\Component\Meta\Dijkstra') |
||
| 54 | ->disableOriginalConstructor() |
||
| 55 | ->getMock(); |
||
| 56 | $this->dijkstra->expects($this->once()) |
||
| 57 | ->method('setMap') |
||
| 58 | ->with($laMappa); |
||
| 59 | $this->dijkstra->expects($this->once()) |
||
| 60 | ->method('shortestPaths') |
||
| 61 | ->will($this->returnValue([[ |
||
| 62 | 'start', |
||
| 63 | 'end' |
||
| 64 | ]])); |
||
| 65 | |||
| 66 | $this->walker = new DijkstraWalker( |
||
| 67 | $this->mapper, |
||
| 68 | $this->dijkstra |
||
| 69 | ); |
||
| 70 | |||
| 71 | $this->walker->buildPathBetween('start', 'end'); |
||
| 72 | |||
| 73 | $pathFound = $this->walker->getPath(); |
||
| 74 | |||
| 75 | $this->assertEquals( |
||
| 76 | '_embedded.fine', |
||
| 77 | $pathFound |
||
| 78 | ); |
||
| 81 |