-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from FriendsOfSymfony/src-test-coverage
Add tests for src/Test
- Loading branch information
Showing
4 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCache package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCache\Tests\Unit\Test\PHPUnit; | ||
|
||
use FOS\HttpCache\Test\PHPUnit\IsCacheHitConstraint; | ||
|
||
class IsCacheHitConstraintTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var IsCacheHitConstraint | ||
*/ | ||
private $constraint; | ||
|
||
public function setUp() | ||
{ | ||
$this->constraint = new IsCacheHitConstraint('cache-header'); | ||
} | ||
|
||
/** | ||
* @expectedException \PHPUnit_Framework_ExpectationFailedException | ||
*/ | ||
public function testMatches() | ||
{ | ||
$response = \Mockery::mock('\Guzzle\Http\Message\Response[getHeader]', array(null)) | ||
->shouldReceive('getHeader') | ||
->once() | ||
->andReturn('MISS') | ||
->getMock(); | ||
|
||
$this->constraint->evaluate($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCache package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCache\Tests\Unit\Test\PHPUnit; | ||
|
||
use FOS\HttpCache\Test\PHPUnit\IsCacheMissConstraint; | ||
|
||
class IsCacheMissConstraintTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var IsCacheMissConstraint | ||
*/ | ||
private $constraint; | ||
|
||
public function setUp() | ||
{ | ||
$this->constraint = new IsCacheMissConstraint('cache-header'); | ||
} | ||
|
||
/** | ||
* @expectedException \PHPUnit_Framework_ExpectationFailedException | ||
*/ | ||
public function testMatches() | ||
{ | ||
$response = \Mockery::mock('\Guzzle\Http\Message\Response[getHeader]', array(null)) | ||
->shouldReceive('getHeader') | ||
->once() | ||
->andReturn('HIT') | ||
->getMock(); | ||
|
||
$this->constraint->evaluate($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCache package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCache\Tests\Unit\Test\Proxy; | ||
|
||
use FOS\HttpCache\Test\Proxy\VarnishProxy; | ||
|
||
class VarnishTestCaseTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \InvalidArgumentException | ||
* @expectedExceptionMessage Cannot find config file: nope.vcl | ||
*/ | ||
public function testInvalidConfigFileThrowsException() | ||
{ | ||
new VarnishProxy('nope.vcl'); | ||
} | ||
|
||
public function testStart() | ||
{ | ||
$proxy = new VarnishProxyMock('config.vcl'); | ||
$proxy->setBinary('/usr/sbin/varnishd'); | ||
$proxy->setConfigDir('/my/varnish/dir'); | ||
$proxy->setIp('192.168.0.1'); | ||
$proxy->setManagementPort(1331); | ||
$proxy->setCacheDir('/tmp/cache/dir'); | ||
$proxy->start(); | ||
|
||
$this->assertEquals('/usr/sbin/varnishd', $proxy->command); | ||
$this->assertEquals( | ||
array( | ||
'-a', '192.168.0.1:6181', | ||
'-T', '192.168.0.1:1331', | ||
'-f', 'config.vcl', | ||
'-n', '/tmp/cache/dir', | ||
'-p', 'vcl_dir=/my/varnish/dir', | ||
'-P', '/tmp/foshttpcache-varnish.pid', | ||
), | ||
$proxy->arguments | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage Caching proxy cannot be reached at 127.0.0.1:6181 | ||
*/ | ||
public function testWaitThrowsException() | ||
{ | ||
$proxy = new VarnishProxyMock('config.vcl'); | ||
$proxy->wait = false; | ||
|
||
$proxy->start(); | ||
} | ||
} | ||
|
||
class VarnishProxyMock extends VarnishProxy | ||
{ | ||
public $command; | ||
public $arguments; | ||
public $wait = true; | ||
|
||
public function setConfigFile($configFile) | ||
{ | ||
$this->configFile = $configFile; | ||
} | ||
|
||
protected function runCommand($command, array $arguments) | ||
{ | ||
$this->command = $command; | ||
$this->arguments = $arguments; | ||
} | ||
|
||
protected function wait($timeout, $callback) | ||
{ | ||
return $this->wait; | ||
} | ||
} |