PHP Classes

File: test/RemoteFetchTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski  >  Certainty  >  test/RemoteFetchTest.php  >  Download  
File: test/RemoteFetchTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Certainty
Manage SSL certificate authority file used by PHP
Author: By
Last change:
Date: 3 years ago
Size: 1,540 bytes
 

Contents

Class file image Download
<?php
namespace ParagonIE\Certainty\Tests;


use
ParagonIE\Certainty\RemoteFetch;
use
PHPUnit\Framework\TestCase;

class
RemoteFetchTest extends TestCase
{
   
/** @var string */
   
protected $dir;

    public function
setUp()
    {
        if (\
getenv('TRAVIS')) {
           
$this->markTestSkipped('Unknown GnuTLS errors are breaking TravisCI but the tests succeed locally.');
        }
       
$this->dir = __DIR__ . '/static/data-remote';
        if (!\
is_dir($this->dir)) {
            \
mkdir($this->dir);
        }
    }

    public function
tearDown()
    {
        \
unlink($this->dir . '/ca-certs.json');
        \
unlink($this->dir . '/ca-certs.cache');
        foreach(\
glob($this->dir . '/*.pem') as $f) {
           
$real = \realpath($f);
            if (\
strpos($real, $this->dir) === 0) {
                \
unlink($f);
            }
        }
    }

   
/**
     * @covers RemoteFetch
     */
   
public function testRemoteFetch()
    {
       
$this->assertFalse(\file_exists($this->dir . '/ca-certs.json'));
       
$fetch = new RemoteFetch($this->dir);
       
$fetch->getLatestBundle();
       
$this->assertTrue(\file_exists($this->dir . '/ca-certs.json'));

       
// Force a cache expiration
       
\file_put_contents(
           
$this->dir . '/ca-certs.cache',
            (new \
DateTime())
                ->
sub(new \DateInterval('PT06H'))
                ->
format(\DateTime::ATOM)
        );
       
$fetch->setCacheTimeout(new \DateInterval('PT01M'));
       
$this->assertTrue($fetch->cacheExpired());
    }
}

For more information send a message to info at phpclasses dot org.