~ballot/wordpress/openstack-objectstorage-bis

« back to all changes in this revision

Viewing changes to vendor/guzzlehttp/guzzle/tests/Cookie/FileCookieJarTest.php

  • Committer: Thomas Cuthbert
  • Date: 2020-04-23 05:22:45 UTC
  • Revision ID: thomas.cuthbert@canonical.com-20200423052245-1jxao3mw31w435js
[,r=trivial] bionic composer vendor update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
namespace GuzzleHttp\Tests\CookieJar;
4
 
 
5
 
use GuzzleHttp\Cookie\FileCookieJar;
6
 
use GuzzleHttp\Cookie\SetCookie;
7
 
 
8
 
/**
9
 
 * @covers GuzzleHttp\Cookie\FileCookieJar
10
 
 */
11
 
class FileCookieJarTest extends \PHPUnit_Framework_TestCase
12
 
{
13
 
    private $file;
14
 
 
15
 
    public function setUp()
16
 
    {
17
 
        $this->file = tempnam('/tmp', 'file-cookies');
18
 
    }
19
 
 
20
 
    /**
21
 
     * @expectedException \RuntimeException
22
 
     */
23
 
    public function testValidatesCookieFile()
24
 
    {
25
 
        file_put_contents($this->file, 'true');
26
 
        new FileCookieJar($this->file);
27
 
    }
28
 
 
29
 
    public function testLoadsFromFileFile()
30
 
    {
31
 
        $jar = new FileCookieJar($this->file);
32
 
        $this->assertEquals([], $jar->getIterator()->getArrayCopy());
33
 
        unlink($this->file);
34
 
    }
35
 
 
36
 
    public function testPersistsToFileFile()
37
 
    {
38
 
        $jar = new FileCookieJar($this->file);
39
 
        $jar->setCookie(new SetCookie([
40
 
            'Name'    => 'foo',
41
 
            'Value'   => 'bar',
42
 
            'Domain'  => 'foo.com',
43
 
            'Expires' => time() + 1000
44
 
        ]));
45
 
        $jar->setCookie(new SetCookie([
46
 
            'Name'    => 'baz',
47
 
            'Value'   => 'bar',
48
 
            'Domain'  => 'foo.com',
49
 
            'Expires' => time() + 1000
50
 
        ]));
51
 
        $jar->setCookie(new SetCookie([
52
 
            'Name'    => 'boo',
53
 
            'Value'   => 'bar',
54
 
            'Domain'  => 'foo.com',
55
 
        ]));
56
 
 
57
 
        $this->assertEquals(3, count($jar));
58
 
        unset($jar);
59
 
 
60
 
        // Make sure it wrote to the file
61
 
        $contents = file_get_contents($this->file);
62
 
        $this->assertNotEmpty($contents);
63
 
 
64
 
        // Load the cookieJar from the file
65
 
        $jar = new FileCookieJar($this->file);
66
 
 
67
 
        // Weeds out temporary and session cookies
68
 
        $this->assertEquals(2, count($jar));
69
 
        unset($jar);
70
 
        unlink($this->file);
71
 
    }
72
 
}