Skip to content

Commit

Permalink
Merge pull request dotkernel#6 from poprazvan17/1.0
Browse files Browse the repository at this point in the history
implemented phpUnit tests, phpcs and psalm
  • Loading branch information
alexmerlin committed Aug 10, 2023
2 parents 6512957 + c3c357e commit 5079466
Show file tree
Hide file tree
Showing 22 changed files with 825 additions and 106 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run phpcs checks

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run phpcs checks
run: vendor/bin/phpcs
46 changes: 46 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run static analysis

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
47 changes: 47 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
- push

name: Run PHPUnit tests

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run PHPUnit tests
run: vendor/bin/phpunit --colors=always
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
composer.lock
.idea/
.DS_Store
/src/.DS_Store
/src/.DS_Store
.phpunit.result.cache
.phpcs-cache
2 changes: 1 addition & 1 deletion OSSMETADATA
Original file line number Diff line number Diff line change
@@ -1 +1 @@
osslifecycle=active
osslifecycle=active
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# dot-data-fixtures

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-data-fixtures)

![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-data-fixtures/1.0.0)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-data-fixtures/1.1.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/blob/1.0/LICENSE)

[![Build Static](https://github.com/dotkernel/dot-data-fixtures/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-data-fixtures/actions/workflows/static-analysis.yml)

[![SymfonyInsight](https://insight.symfony.com/projects/6bac345c-9548-47ec-ab4a-25773a98ed03/big.svg)](https://insight.symfony.com/projects/6bac345c-9548-47ec-ab4a-25773a98ed03)

This package provides a CLI interface for interacting with doctrine/data-fixtures.

**Executing fixtures will **append** data to the tables.**

### Requirements
- PHP >= 7.4
- PHP >= 8.1
- doctrine/data-fixtures => 1.5

## Installation
Expand Down
33 changes: 29 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,40 @@
"mezzio"
],
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0",
"doctrine/data-fixtures": "^1.5"
"php": "~8.1.0 || ~8.2.0",
"doctrine/data-fixtures": "^1.5",
"doctrine/orm": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^10.2",
"laminas/laminas-coding-standard": "^2.5",
"vimeo/psalm": "^5.13"
},
"autoload": {
"psr-4": {
"Dot\\DataFixtures\\": "src"
"Dot\\DataFixtures\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DotTest\\DataFixtures\\": "test/"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"static-analysis": "psalm --shepherd --stats"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
20 changes: 20 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
15 changes: 15 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="Dot Data Fixtures Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
findUnusedBaselineEntry="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
61 changes: 28 additions & 33 deletions src/Command/ExecuteFixturesCommand.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
<?php

declare(strict_types=1);

namespace Dot\DataFixtures\Command;


use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\Input;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

/**
* Class ExecuteFixturesCommand
* @package Dot\DataFixtures\Command
*/
use function sprintf;

use const DIRECTORY_SEPARATOR;

class ExecuteFixturesCommand extends Command
{
/** @var string */
protected static $defaultName = 'fixtures:execute';

private EntityManager $entityManager;
private Loader $loader;
private ORMPurger $purger;
private ORMExecutor $executor;

private string $path;

/**
* ExecuteFixturesCommand constructor.
* @param EntityManager $entityManager
* @param string $path
*/
public function __construct(EntityManager $entityManager, string $path)
{
public function __construct(
EntityManager $entityManager,
Loader $loader,
ORMPurger $purger,
ORMExecutor $executor,
string $path
) {
parent::__construct(self::$defaultName);

$this->entityManager = $entityManager;
$this->path = $path;
$this->loader = $loader;
$this->purger = $purger;
$this->executor = $executor;
$this->path = $path;
}

/**
* @return void
*/
protected function configure(): void
{
$this->setName(self::$defaultName)
Expand All @@ -56,30 +58,23 @@ protected function configure(): void
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$loader = new Loader();
$purger = new ORMPurger($this->entityManager);

$executor = new ORMExecutor($this->entityManager, $purger);
$this->purger->setEntityManager($this->entityManager);
$this->executor->setPurger($this->purger);

if ($input->getOption('class') === false) {
$loader->loadFromDirectory($this->path);
if (empty($input->getOptions())) {
$this->loader->loadFromDirectory($this->path);
} else {
$loader->loadFromFile($this->path . DIRECTORY_SEPARATOR . $input->getOption('class') . '.php');
$this->loader->loadFromFile($this->path . DIRECTORY_SEPARATOR . $input->getOption('class') . '.php');
}

$fixtures = $loader->getFixtures();
$fixtures = $this->loader->getFixtures();

$executor->execute($fixtures, true);
$this->executor->execute($fixtures, true);

foreach ($fixtures as $fixture) {
$output->writeln(sprintf('<info>Executing %s </info>', get_class($fixture)));
$output->writeln(sprintf('<info>Executing %s </info>', $fixture::class));
}

$output->writeln("<info>Fixtures have been loaded.</info>");
Expand Down
Loading

0 comments on commit 5079466

Please sign in to comment.