Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global improvements #25

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/code_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Code_Checks
on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4']

name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v2

# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
coverage: none

- run: composer install --no-progress
- run: vendor/bin/phpunit

test_lowest_dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v1
with:
php-version: 7.1
coverage: none

- run: composer update --no-progress --prefer-lowest
- run: vendor/bin/phpunit
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
"email": "[email protected]"
}],
"require": {
"php": ">=5.3.2",
"symfony/http-foundation": "~2.0|~3.0|~4.0"
"php": ">=7.1.3",
"symfony/http-foundation": "~4.0|~5.0"
},
"require-dev": {
"sami/sami": "^3.3",
"ext-curl": "*",
"phpunit/phpunit": "^4.8|^5.5|^6.5|^7.0"
"phpunit/phpunit": "^5.5|^6.5|^7.0",
"sami/sami": "^4.1",
"symfony/process": "~4.0|~5.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="false"
bootstrap="bootstrap.php"
>
Expand Down
2 changes: 0 additions & 2 deletions sami_configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
include 'vendor/autoload.php';

use Sami\Sami;
use Sami\Version\GitVersionCollection;
use Symfony\Component\Finder\Finder;

$iterator = Finder::create()
Expand All @@ -14,7 +13,6 @@

return new Sami($iterator, array(
'title' => 'PHP-dataURI API',
'theme' => 'enhanced',
'build_dir' => __DIR__.'/docs/source/API/API',
'cache_dir' => __DIR__.'/docs/source/API/API/cache',
'default_opened_level' => 2,
Expand Down
46 changes: 44 additions & 2 deletions tests/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use DataURI\Data;
use DataURI\Exception\TooLongDataException;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

/**
*
Expand All @@ -33,6 +34,26 @@
*/
class DataTest extends TestCase
{
/**
* @var string
*/
private const LOCALHOST = 'localhost:8000';

/** @var Process */
private static $process;

public static function setUpBeforeClass()
{
self::$process = new Process(sprintf('exec php -S %s -t %s', static::LOCALHOST, __DIR__));
self::$process->start();

usleep(100000); //wait for server to get going
}

public static function tearDownAfterClass()
{
self::$process->stop();
}

public function testTooLongException()
{
Expand Down Expand Up @@ -129,13 +150,17 @@ public function testBuildFromFile()
*/
public function testBuildFromUrlShouldThrowFileNotFoundException()
{
$url = 'http://via.placeholder.com/x150.png';
$this->skipIfLocalWebServerDown();

$url = sprintf('http://%s/unknown.png', static::LOCALHOST);
Data::buildFromUrl($url);
}

public function testBuildFromUrl()
{
$url = 'http://via.placeholder.com/350x150.png';
$this->skipIfLocalWebServerDown();

$url = sprintf('http://%s/smile.png', static::LOCALHOST);
$dataURI = Data::buildFromUrl($url);
$this->assertInstanceOf('DataURI\Data', $dataURI);
$this->assertEquals('image/png', $dataURI->getMimeType());
Expand Down Expand Up @@ -185,4 +210,21 @@ private function createEmptyFile($filename)
fwrite($handle, '');
fclose($handle);
}

private function skipIfLocalWebServerDown()
{
$url = sprintf('http://%s/', static::LOCALHOST);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if (0 === $httpcode) {
$this->markTestSkipped('The local web server is (still) down.');
}
}
}