|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the FOSHttpCache package. |
| 5 | + * |
| 6 | + * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace FOS\HttpCache\Tests\Functional; |
| 13 | + |
| 14 | +use FOS\HttpCache\ProxyClient\Symfony; |
| 15 | +use FOS\HttpCache\Test\SymfonyTestCase; |
| 16 | + |
| 17 | +/** |
| 18 | + * @group webserver |
| 19 | + * @group symfony |
| 20 | + */ |
| 21 | +class SymfonyProxyClientTest extends SymfonyTestCase |
| 22 | +{ |
| 23 | + public function setUp() |
| 24 | + { |
| 25 | + /* |
| 26 | + * We did not figure out how to run this test with hhvm. Help welcome! |
| 27 | + * On travis, connection is closed after the headers are sent without providing |
| 28 | + * anything in either the hhvm or apache log. |
| 29 | + */ |
| 30 | + if (defined('HHVM_VERSION')) { |
| 31 | + $this->markTestSkipped('Test not working with hhvm as backend server'); |
| 32 | + } |
| 33 | + |
| 34 | + parent::setUp(); |
| 35 | + } |
| 36 | + |
| 37 | + public function testPurge() |
| 38 | + { |
| 39 | + $this->assertMiss($this->getResponse('/symfony.php/cache')); |
| 40 | + $this->assertHit($this->getResponse('/symfony.php/cache')); |
| 41 | + |
| 42 | + $this->getProxyClient()->purge('/symfony.php/cache')->flush(); |
| 43 | + $this->assertMiss($this->getResponse('/symfony.php/cache')); |
| 44 | + } |
| 45 | + |
| 46 | + public function testPurgeContentType() |
| 47 | + { |
| 48 | + $json = array('Accept' => 'application/json'); |
| 49 | + $html = array('Accept' => 'text/html'); |
| 50 | + |
| 51 | + $response = $this->getResponse('/symfony.php/negotiation', $json); |
| 52 | + $this->assertMiss($response); |
| 53 | + $this->assertEquals('application/json', $response->getContentType()); |
| 54 | + $this->assertHit($this->getResponse('/symfony.php/negotiation', $json)); |
| 55 | + |
| 56 | + $response = $this->getResponse('/symfony.php/negotiation', $html); |
| 57 | + $this->assertContains('text/html', $response->getContentType()); |
| 58 | + $this->assertMiss($response); |
| 59 | + $this->assertHit($this->getResponse('/symfony.php/negotiation', $html)); |
| 60 | + |
| 61 | + $this->getResponse('/symfony.php/negotiation'); |
| 62 | + $this->getProxyClient()->purge('/symfony.php/negotiation')->flush(); |
| 63 | + $this->assertMiss($this->getResponse('/symfony.php/negotiation', $json)); |
| 64 | + $this->assertMiss($this->getResponse('/symfony.php/negotiation', $html)); |
| 65 | + } |
| 66 | + |
| 67 | + public function testPurgeHost() |
| 68 | + { |
| 69 | + $symfony = new Symfony(array('http://127.0.0.1:' . $this->getCachingProxyPort()), null, null, array('purge_method' => 'NOTIFY')); |
| 70 | + |
| 71 | + $this->getResponse('/symfony.php/cache'); |
| 72 | + |
| 73 | + $symfony->purge('http://localhost:8080/symfony.php/cache')->flush(); |
| 74 | + $this->assertMiss($this->getResponse('/symfony.php/cache')); |
| 75 | + } |
| 76 | + |
| 77 | + public function testRefresh() |
| 78 | + { |
| 79 | + $this->assertMiss($this->getResponse('/symfony.php/cache')); |
| 80 | + $response = $this->getResponse('/symfony.php/cache'); |
| 81 | + $this->assertHit($response); |
| 82 | + |
| 83 | + $this->getProxyClient()->refresh('/symfony.php/cache')->flush(); |
| 84 | + usleep(100); |
| 85 | + $refreshed = $this->getResponse('/symfony.php/cache'); |
| 86 | + $this->assertGreaterThan((float) $response->getBody(true), (float) $refreshed->getBody(true)); |
| 87 | + } |
| 88 | + |
| 89 | + public function testRefreshContentType() |
| 90 | + { |
| 91 | + $json = array('Accept' => 'application/json'); |
| 92 | + $html = array('Accept' => 'text/html'); |
| 93 | + |
| 94 | + $this->getProxyClient()->refresh('/symfony.php/negotiation', $json)->flush(); |
| 95 | + |
| 96 | + $this->assertHit($this->getResponse('/symfony.php/negotiation', $json)); |
| 97 | + $this->assertMiss($this->getResponse('/symfony.php/negotiation', $html)); |
| 98 | + } |
| 99 | +} |
0 commit comments