Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simple FileProcessor test, QA: PhpStan, Sniffer, Travis
  • Loading branch information
josefbenjac committed Oct 12, 2017
1 parent c488162 commit cef086f
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 52 deletions.
66 changes: 66 additions & 0 deletions .travis.yml
@@ -0,0 +1,66 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2

before_install:
# turn off XDebug
- phpenv config-rm xdebug.ini || return 0

install:
# Composer
- travis_retry composer install --no-progress --prefer-dist

script:
# Nette/Tester
- composer run-script tester

jobs:
include:
- env: title="Lowest Dependencies 5.6"
php: 5.6
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tester

- env: title="Lowest Dependencies 7.1"
php: 7.1
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tester

- stage: Quality Assurance
php: 7.1
script:
- composer run-script qa

- stage: Test Coverage
php: 7.1
script:
- composer run-script coverage
after_script:
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- php coveralls.phar --verbose --config tests/.coveralls.yml

- stage: Phpstan
php: 7.1
script:
- composer run-script phpstan-install
- composer run-script phpstan

allow_failures:
- stage: Test Coverage

after_failure:
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done

sudo: false

cache:
directories:
- $HOME/.composer/cache
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Contributte
Copyright (c) 2017 Contributte

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 17 additions & 12 deletions README.md
@@ -1,18 +1,23 @@
Usage
-----

"scripts": {
"scripts": {
"post-install-cmd": [
"Contributte\\Neonizer\\NeonizerExtension::process"
"Contributte\\Neonizer\\NeonizerExtension::process"
],
"post-update-cmd": [
"Contributte\\Neonizer\\NeonizerExtension::process"
"Contributte\\Neonizer\\NeonizerExtension::process"
]
},
"extra": {
"neonizer": [
{
"file": "files/config.neon"
}
]
}
},
"extra": {
"neonizer": {
"files": [
{
"dist-file": "files/config.neon.dist"
},
{
"dist-file": "files/config.neon.dist",
"file": "files/config.json"
}
]
}
}
43 changes: 14 additions & 29 deletions composer.json
@@ -1,13 +1,9 @@
{
"name": "contributte/neonizer",
"description": "Neonizer",
"keywords": [
"nette"
],
"keywords": ["nette", "composer"],
"type": "library",
"license": [
"MIT"
],
"license": ["MIT"],
"homepage": "https://github.com/contributte/migrations",
"authors": [
{
Expand All @@ -17,13 +13,13 @@
],
"require": {
"php": ">=5.6",
"nette/neon": "^2.4"
"nette/neon": "^2.4.2"
},
"require-dev": {
"ninjify/qa": "~0.4.0",
"ninjify/nunjuck": "~0.1.4",
"ninjify/nunjuck": "~0.2.0",
"composer/composer": "^1.5",
"symfony/yaml": "^3.3"
"mockery/mockery": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,29 +32,18 @@
"codesniffer src tests"
],
"tester": [
"tester -s -p php --colors 1 -c tests/php-unix.ini tests/cases"
"tester -s -p php --colors 1 -C tests/cases"
],
"tester-coverage": [
"tester -s -p php --colors 1 -c tests/php-unix.ini -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases"
"coverage": [
"tester -s -p php --colors 1 -C -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases"
],
"post-install-cmd": [
"Contributte\\Neonizer\\NeonizerExtension::process"
"phpstan-install": [
"mkdir -p temp/phpstan",
"composer require -d temp/phpstan phpstan/phpstan:0.8.5",
"composer require -d temp/phpstan phpstan/phpstan-nette:0.8.3"
],
"post-update-cmd": [
"Contributte\\Neonizer\\NeonizerExtension::process"
"phpstan": [
"temp/phpstan/vendor/bin/phpstan analyse -l 7 -c phpstan.neon src"
]
},
"extra": {
"neonizer": {
"files": [
{
"dist-file": "files/config.neon.dist"
},
{
"dist-file": "files/config.neon.dist",
"file": "files/config.json"
}
]
}
}
}
9 changes: 0 additions & 9 deletions files/config.neon.dist

This file was deleted.

5 changes: 5 additions & 0 deletions phpstan.neon
@@ -0,0 +1,5 @@
includes:
- temp/phpstan/vendor/phpstan/phpstan-nette/extension.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/rules.neon

parameters:
2 changes: 1 addition & 1 deletion src/FileProcessor.php
Expand Up @@ -126,7 +126,7 @@ protected function processFile(array $content, FileConfig $config)
{
$encoder = $this->encoderFactory->create($config->getOutputType());
$content = $encoder->encode($content);
$this->saveFile($content, $config->getFile());
$this->saveFile((string) $content, $config->getFile());
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/.coveralls.yml
@@ -0,0 +1,4 @@
# for php-coveralls
service_name: travis-ci
coverage_clover: coverage.xml
json_path: coverage.json
10 changes: 10 additions & 0 deletions tests/.gitignore
@@ -0,0 +1,10 @@
# Folders - recursive
*.expected
*.actual

# Folders
/tmp

# Files
/*.log
/*.html
11 changes: 11 additions & 0 deletions tests/bootstrap.php
@@ -0,0 +1,11 @@
<?php

use Ninjify\Nunjuck\Environment;

if (@!include __DIR__ . '/../vendor/autoload.php') {
echo 'Install Nette Tester using `composer update --dev`';
exit(1);
}

// Configure environment
Environment::setup(__DIR__);
92 changes: 92 additions & 0 deletions tests/cases/FileProcessorTest.phpt
@@ -0,0 +1,92 @@
<?php

/**
* Test: FileProcessor
*/

use Composer\IO\IOInterface;
use Contributte\Neonizer\Config\FileConfig;
use Contributte\Neonizer\Decoder\DecoderFactory;
use Contributte\Neonizer\Encoder\EncoderFactory;
use Contributte\Neonizer\FileProcessor;
use Tester\Assert;
use Tester\TestCase;

require_once __DIR__ . '/../bootstrap.php';

/**
* @testCase
*/
class FileProcessorTest extends TestCase
{

/**
* @return void
*/
public function testNoInteractive()
{
$generatedFile = __DIR__ . '/../tmp/files/no-interactive.neon';
$config = new FileConfig([
'dist-file' => __DIR__ . '/files/config.neon.dist',
'file' => $generatedFile,
]);

/** @var IOInterface $io */
$io = Mockery::mock(IOInterface::class)
->shouldReceive('isInteractive')
->andReturn(FALSE)
->getMock()
->shouldReceive('write')
->getMock();

$processor = new FileProcessor($io, new EncoderFactory(), new DecoderFactory());
$processor->process($config);

self::assertFiles(__DIR__ . '/files/no-interactive.neon', $generatedFile);
}

/**
* @return void
*/
public function testInteractive()
{
/** @var IOInterface $io */
$io = Mockery::mock(IOInterface::class)
->shouldReceive('isInteractive')
->andReturn(TRUE)
->getMock()
->shouldReceive('ask')
->andReturn('bar')
->getMock()
->shouldReceive('write')
->getMock();
$processor = new FileProcessor($io, new EncoderFactory(), new DecoderFactory());

$generatedFile = __DIR__ . '/../tmp/files/interactive.neon';
$processor->process(new FileConfig([
'dist-file' => __DIR__ . '/files/config.neon.dist',
'file' => $generatedFile,
]));
self::assertFiles(__DIR__ . '/files/interactive.neon', $generatedFile);

$generatedFile = __DIR__ . '/../tmp/files/interactive.json';
$processor->process(new FileConfig([
'dist-file' => __DIR__ . '/files/config.neon.dist',
'file' => $generatedFile,
]));
self::assertFiles(__DIR__ . '/files/interactive.json', $generatedFile);
}

/**
* @param string $expected
* @param string $actual
* @return void
*/
private static function assertFiles($expected, $actual)
{
Assert::same(file_get_contents($expected), file_get_contents($actual));
}

}

(new FileProcessorTest())->run();
5 changes: 5 additions & 0 deletions tests/cases/files/config.neon.dist
@@ -0,0 +1,5 @@
mode: debug
database:
user: root
pass:
dbname: neonizer
8 changes: 8 additions & 0 deletions tests/cases/files/interactive.json
@@ -0,0 +1,8 @@
{
"mode": "bar",
"database": {
"user": "bar",
"pass": "bar",
"dbname": "bar"
}
}
7 changes: 7 additions & 0 deletions tests/cases/files/interactive.neon
@@ -0,0 +1,7 @@
# This file is auto-generated by composer
mode: bar
database:
user: bar
pass: bar
dbname: bar

7 changes: 7 additions & 0 deletions tests/cases/files/no-interactive.neon
@@ -0,0 +1,7 @@
# This file is auto-generated by composer
mode: debug
database:
user: root
pass: null
dbname: neonizer

0 comments on commit cef086f

Please sign in to comment.