3
namespace GuzzleHttp\Tests\CookieJar;
5
use GuzzleHttp\Cookie\FileCookieJar;
6
use GuzzleHttp\Cookie\SetCookie;
9
* @covers GuzzleHttp\Cookie\FileCookieJar
11
class FileCookieJarTest extends \PHPUnit_Framework_TestCase
15
public function setUp()
17
$this->file = tempnam('/tmp', 'file-cookies');
21
* @expectedException \RuntimeException
23
public function testValidatesCookieFile()
25
file_put_contents($this->file, 'true');
26
new FileCookieJar($this->file);
29
public function testLoadsFromFileFile()
31
$jar = new FileCookieJar($this->file);
32
$this->assertEquals([], $jar->getIterator()->getArrayCopy());
36
public function testPersistsToFileFile()
38
$jar = new FileCookieJar($this->file);
39
$jar->setCookie(new SetCookie([
42
'Domain' => 'foo.com',
43
'Expires' => time() + 1000
45
$jar->setCookie(new SetCookie([
48
'Domain' => 'foo.com',
49
'Expires' => time() + 1000
51
$jar->setCookie(new SetCookie([
54
'Domain' => 'foo.com',
57
$this->assertEquals(3, count($jar));
60
// Make sure it wrote to the file
61
$contents = file_get_contents($this->file);
62
$this->assertNotEmpty($contents);
64
// Load the cookieJar from the file
65
$jar = new FileCookieJar($this->file);
67
// Weeds out temporary and session cookies
68
$this->assertEquals(2, count($jar));