Skip to content

Commit

Permalink
Refactoring to support Nette v3
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x authored and Milan Felix Šulc committed Jul 9, 2019
1 parent 608e36b commit bb104de
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 165 deletions.
24 changes: 16 additions & 8 deletions .docs/README.md
@@ -1,15 +1,23 @@
# Fixtures
# Nettrine Fixtures

[Doctrine\DataFixtures](https://github.com/doctrine/data-fixtures) for Nette Framework

## Content

- [Usage - how to register](#usage)
- [Extension - how to configure](#configuration)
- [Command - how to use command](#command)
- [Fixture - how to write fixtures](#fixture)
- [Setup](#usage)
- [Configuration](#configuration)
- [Usage](#command)
- [Fixture - create own fixtures](#fixture)

## Usage
## Setup

Install package

At first you should register `FixturesExtension` at your config file.
```bash
composer require nettrine/fixtures
```

Register extension

```yaml
extensions:
Expand Down Expand Up @@ -39,7 +47,7 @@ fixtures:
- ...
```

## Command
## Usage

The **doctrine:fixtures:load** command loads data fixtures from your configuration by default:

Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -5,6 +5,7 @@ tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
Makefile export-ignore
phpstan.neon export-ignore
README.md export-ignore
ruleset.xml export-ignore
39 changes: 17 additions & 22 deletions .travis.yml
@@ -1,57 +1,52 @@
language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- nightly

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

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

script:
# Tests
- composer run-script tests
- make tests # Tests

jobs:
include:
- env: title="Lowest Dependencies 7.1"
php: 7.1
- env: title="Lowest Dependencies 7.3"
php: 7.3
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
script:
- composer run-script tests
- make tests

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

- stage: Phpstan
php: 7.1
script:
- composer run-script phpstan
- make qa

- stage: Test Coverage
if: branch = master AND type = push
php: 7.1
php: 7.3
script:
- composer run-script coverage
- make coverage
after_script:
- composer global require php-coveralls/php-coveralls ^2.1.0
- ~/.composer/vendor/bin/php-coveralls --verbose --config tests/.coveralls.yml

- stage: Outdated Dependencies
if: branch = master AND type = cron
php: 7.1
php: 7.3
script:
- composer outdated --direct --strict
- composer outdated --direct

allow_failures:
- stage: Test Coverage
- php: 7.4snapshot
- php: nightly

sudo: false

Expand Down
27 changes: 27 additions & 0 deletions Makefile
@@ -0,0 +1,27 @@
.PHONY: qa lint cs csf phpstan tests coverage

all:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

vendor: composer.json composer.lock
composer install

qa: lint phpstan cs

lint: vendor
vendor/bin/linter src tests

cs: vendor
vendor/bin/codesniffer src tests

csf: vendor
vendor/bin/codefixer src tests

phpstan: vendor
vendor/bin/phpstan analyse -l max -c phpstan.neon src

tests: vendor
vendor/bin/phpunit tests --cache-result-file=tests/tmp/phpunit.cache --colors=always

coverage: vendor
vendor/bin/phpdbg -qrr vendor/bin/phpunit tests --cache-result-file=tests/tmp/phpunit.cache --colors=always -c tests/coverage.xml
33 changes: 11 additions & 22 deletions README.md
@@ -1,8 +1,6 @@
# Fixtures
# Nettrine Fixtures

[Doctrine\DataFixtures](https://github.com/doctrine/data-fixtures) to Nette Framework

-----
[Doctrine\DataFixtures](https://github.com/doctrine/data-fixtures) for Nette Framework

[![Build Status](https://img.shields.io/travis/nettrine/fixtures.svg?style=flat-square)](https://travis-ci.org/nettrine/fixtures)
[![Code coverage](https://img.shields.io/coveralls/nettrine/fixtures.svg?style=flat-square)](https://coveralls.io/r/nettrine/fixtures)
Expand All @@ -16,26 +14,19 @@

[![Join the chat](https://img.shields.io/gitter/room/nettrine/nettrine.svg?style=flat-square)](https://gitter.im/nettrine/nettrine)

## Install
## Documentation

```sh
composer require nettrine/fixtures
```
- [Setup](.docs/README.md#usage)
- [Configuration](.docs/README.md#configuration)
- [Usage](.docs/README.md#command)
- [Fixture - create own fixtures](.docs/README.md#fixture)

## Versions

| State | Version | Branch | PHP |
|-------------|---------------|----------|----------|
| development | `^0.5` | `master` | `>= 7.1` |
| stable | `^0.4` | `master` | `>= 7.1` |
| stable | `^0.2` | `master` | `>= 5.6` |

## Overview

- [Usage - how to register](https://github.com/nettrine/fixtures/blob/master/.docs/README.md#usage)
- [Extension - how to configure](https://github.com/nettrine/fixtures/blob/master/.docs/README.md#configuration)
- [Command - how to use command](https://github.com/nettrine/fixtures/blob/master/.docs/README.md#command)
- [Fixture - how to write fixtures](https://github.com/nettrine/fixtures/blob/master/.docs/README.md#fixture)
| State | Version | Branch | Nette | PHP |
|-------------|---------------|----------|--------|--------|
| development | `^0.5` | `master` | `3.0+` | `^7.2` |
| stable | `^0.4` | `master` | `2.4` | `^7.1` |

## Maintainers

Expand All @@ -60,6 +51,4 @@ composer require nettrine/fixtures
</tbody>
</table>

-----

Thank you for testing, reporting and contributing.
44 changes: 17 additions & 27 deletions composer.json
Expand Up @@ -16,20 +16,21 @@
}
],
"require": {
"php": ">=7.1",
"nette/di": "~2.4.14",
"symfony/console": "^4.2.0",
"php": "^7.2",
"nette/di": "~3.0.0",
"symfony/console": "^4.2.5",
"doctrine/data-fixtures": "^1.3.1",
"doctrine/orm": "^2.6.3"
},
"require-dev": {
"ninjify/qa": "^0.8.0",
"phpunit/phpunit": "^7.5.1",
"mockery/mockery": "^1.2.0",
"phpstan/phpstan-shim": "^0.10.6",
"phpstan/phpstan-deprecation-rules": "^0.10.2",
"phpstan/phpstan-nette": "^0.10.1",
"phpstan/phpstan-strict-rules": "^0.10.1"
"mockery/mockery": "^1.2.2",
"ninjify/qa": "^0.9.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-deprecation-rules": "^0.11.0",
"phpstan/phpstan-nette": "^0.11.0",
"phpstan/phpstan-shim": "^0.11.5",
"phpstan/phpstan-strict-rules": "^0.11.0",
"phpunit/phpunit": "^8.1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -38,30 +39,19 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\Nettrine\\Fixtures\\Cases\\": "tests/cases/"
"Tests\\Cases\\": "tests/cases",
"Tests\\Fixtures\\": "tests/fixtures",
"Tests\\Toolkit\\": "tests/toolkit"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"qa": [
"linter src tests/cases",
"codesniffer src tests/cases"
],
"tests": [
"phpunit tests --colors=always"
],
"coverage": [
"phpdbg -qrr vendor/bin/phpunit tests --colors=always -c tests/coverage.xml"
],
"phpstan": [
"vendor/bin/phpstan analyse -l max -c phpstan.neon src"
]
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "0.5.x-dev"
"dev-next": "0.5.x-dev"
}
}
}

6 changes: 0 additions & 6 deletions phpstan.neon
@@ -1,9 +1,3 @@
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
excludes_analyse:
# Symfony/Console have too magic api
Expand Down
39 changes: 21 additions & 18 deletions ruleset.xml
@@ -1,22 +1,25 @@
<?xml version="1.0"?>
<ruleset name="Nettrine">
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden"/>
</rule>
<ruleset>
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden"/>
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountAfterControlStructure"/>
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountBeforeControlStructure"/>
</rule>

<!-- Specific -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
src=>Nettrine\Fixtures,
tests/cases=>Tests\Nettrine\Fixtures\Cases,
tests/fixtures=>Tests\Nettrine\Fixtures\Fixture
"/>
</properties>
</rule>
<!-- Specific -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="
src=>Nettrine\Fixtures,
tests/cases=>Tests\Cases,
tests/fixtures=>Tests\Fixtures,
tests/toolkit=>Tests\Toolkit
"/>
</properties>
</rule>

<!--Exclude folders -->
<exclude-pattern>/tests/tmp</exclude-pattern>
<!--Exclude folders -->
<exclude-pattern>/tests/tmp</exclude-pattern>
</ruleset>
2 changes: 1 addition & 1 deletion src/Command/LoadDataFixturesCommand.php
Expand Up @@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$fixtures = $this->loader->getFixtures();
if (!$fixtures) {
if ($fixtures === []) {
throw new InvalidArgumentException(
sprintf(
'Could not find any fixtures to load in: %s',
Expand Down
23 changes: 16 additions & 7 deletions src/DI/FixturesExtension.php
Expand Up @@ -3,28 +3,37 @@
namespace Nettrine\Fixtures\DI;

use Nette\DI\CompilerExtension;
use Nette\DI\Extensions\InjectExtension;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nettrine\Fixtures\Command\LoadDataFixturesCommand;
use Nettrine\Fixtures\Loader\FixturesLoader;
use stdClass;

/**
* @property-read stdClass $config
*/
class FixturesExtension extends CompilerExtension
{

/** @var mixed[] */
private $defaults = [
'paths' => [],
];
public function getConfigSchema(): Schema
{
return Expect::structure([
'paths' => Expect::listOf('string'),
]);
}

public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);
$config = $this->config;

$builder->addDefinition($this->prefix('fixturesLoader'))
->setFactory(FixturesLoader::class, [$config['paths']]);
->setFactory(FixturesLoader::class, [$config->paths]);

$builder->addDefinition($this->prefix('loadDataFixturesCommand'))
->setFactory(LoadDataFixturesCommand::class)
->setInject(false)
->addTag(InjectExtension::TAG_INJECT, true)
->addTag('console.command', 'doctrine:fixtures:load');
}

Expand Down

0 comments on commit bb104de

Please sign in to comment.