Esempio n. 1
0
 /**
  * Tests that setting custom options via constructor
  * @return void
  */
 public function testConstructOptions()
 {
     $cookie = new Cookie(array('expires' => 100, 'path' => '/foo', 'domain' => 'www.bar.com', 'secure' => true, 'httponly' => true, 'name' => 'test_name', 'value' => 'test_value'));
     $this->assertEquals(100, $cookie->getExpires());
     $this->assertEquals('/foo', $cookie->getPath());
     $this->assertEquals('www.bar.com', $cookie->getDomain());
     $this->assertTrue($cookie->isSecure());
     $this->assertTrue($cookie->isHttponly());
     $this->assertEquals('test_name', $cookie->getName());
     $this->assertEquals('test_value', $cookie->getValue());
 }
Esempio n. 2
0
 /**
  * Overloads offsetSet to restrict value type
  * @param  int|string      $key
  * @param  \Nimbles\Http\Cookie $value
  * @return void
  * @throws \Nimbles\Http\Cookie\Exception\InvalidInstance
  */
 public function offsetSet($key, $value)
 {
     if (is_string($value)) {
         $value = new Cookie(array('name' => $key, 'value' => $value));
     }
     if (!$value instanceof Cookie) {
         throw new Cookie\Exception\InvalidInstance('Invalid value, must be an instance of Nimbles\\Http\\Cookie');
     }
     if (null === $value->getName()) {
         $value->setName($key);
     }
     return parent::offsetSet($value->getName(), $value);
 }