Jyxo\Time\TimeTest::testSetTimeZone PHP Method

testSetTimeZone() public method

Tests the setTimezone() method.
See also: Jyxo\Time\Time::setTimezone()
public testSetTimeZone ( )
    public function testSetTimeZone()
    {
        $time = Time::get(time(), 'UTC');
        $this->assertNotSame('Europe/Prague', $time->getTimeZone()->getName());
        $time->setTimeZone('Europe/Prague');
        $this->assertSame('Europe/Prague', $time->getTimeZone()->getName());
        $timeZone = new \DateTimeZone('America/Santiago');
        $time->setTimeZone($timeZone);
        $this->assertSame('America/Santiago', $time->getTimeZone()->getName());
        // Invalid timezone
        try {
            $time->setTimeZone('Foo/Bar');
            $this->fail(sprintf('Expected exception %s.', \InvalidArgumentException::class));
        } catch (\PHPUnit_Framework_AssertionFailedError $e) {
            throw $e;
        } catch (\Exception $e) {
            // Correctly thrown exception
            $this->assertInstanceOf(\InvalidArgumentException::class, $e);
        }
    }