Skip to content

Commit 22af158

Browse files
committed
Added ImportConnectorTest.
1 parent e754328 commit 22af158

File tree

2 files changed

+82
-34
lines changed

2 files changed

+82
-34
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
namespace ScriptFUSIONTest\Unit\Porter\Connector;
3+
4+
use ScriptFUSION\Porter\Cache\CacheUnavailableException;
5+
use ScriptFUSION\Porter\Connector\CachingConnector;
6+
use ScriptFUSION\Porter\Connector\Connector;
7+
use ScriptFUSION\Porter\Connector\ImportConnector;
8+
use ScriptFUSION\Porter\Options\EncapsulatedOptions;
9+
use ScriptFUSIONTest\FixtureFactory;
10+
11+
/**
12+
* @see ImportConnector
13+
*/
14+
final class ImportConnectorTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* Tests that when fetching, the specified context, source and options are passed verbatim to the underlying
18+
* connector.
19+
*/
20+
public function testCallGraph()
21+
{
22+
$connector = new ImportConnector(
23+
\Mockery::mock(Connector::class)
24+
->shouldReceive('fetch')
25+
->with(
26+
$context = FixtureFactory::buildConnectionContext(),
27+
$source = 'bar',
28+
$options = \Mockery::mock(EncapsulatedOptions::class)
29+
)->once()
30+
->andReturn($output = 'foo')
31+
->getMock(),
32+
$context
33+
);
34+
35+
self::assertSame($output, $connector->fetch($source, $options));
36+
}
37+
38+
/**
39+
* Tests that when context specifies no cache required and a normal connector is used, fetch succeeds.
40+
*/
41+
public function testFetchCacheDisabled()
42+
{
43+
$connector = new ImportConnector(
44+
\Mockery::mock(Connector::class)
45+
->shouldReceive('fetch')
46+
->andReturn($output = 'foo')
47+
->getMock(),
48+
FixtureFactory::buildConnectionContext()
49+
);
50+
51+
self::assertSame($output, $connector->fetch('bar'));
52+
}
53+
54+
/**
55+
* Tests that when context specifies cache required and a caching connector is used, fetch succeeds.
56+
*/
57+
public function testFetchCacheEnabled()
58+
{
59+
$connector = new ImportConnector(
60+
\Mockery::mock(CachingConnector::class)
61+
->shouldReceive('fetch')
62+
->andReturn($output = 'foo')
63+
->getMock(),
64+
FixtureFactory::buildConnectionContext(true)
65+
);
66+
67+
self::assertSame($output, $connector->fetch('bar'));
68+
}
69+
70+
/**
71+
* Tests that when context specifies cache required but a non-caching connector is used, an exception is thrown.
72+
*/
73+
public function testFetchCacheEnabledButNotAvailable()
74+
{
75+
$this->setExpectedException(CacheUnavailableException::class);
76+
77+
new ImportConnector(
78+
\Mockery::mock(Connector::class),
79+
FixtureFactory::buildConnectionContext(true)
80+
);
81+
}
82+
}

test/Unit/Porter/Connector/SuperConnectorTest.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)