Skip to content

Commit cf5b6d0

Browse files
authored
Merge pull request #1 from TomHAnderson/feature/first-release
Ready for phpcs and unittests
2 parents 967042e + 02a6a36 commit cf5b6d0

26 files changed

+925
-57
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Coding Standards"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*.x"
7+
- "main"
8+
push:
9+
branches:
10+
- "*.x"
11+
- "main"
12+
13+
jobs:
14+
coding-standards:
15+
name: "Coding Standards"
16+
uses: "doctrine/.github/.github/workflows/[email protected]"
17+
with:
18+
php-version: '8.0'
19+
composer-options: '--prefer-dist --ignore-platform-req=php'
20+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*.x"
7+
- "main"
8+
push:
9+
branches:
10+
- "*.x"
11+
- "main"
12+
13+
jobs:
14+
phpunit:
15+
name: "PHPUnit"
16+
runs-on: "ubuntu-20.04"
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php-version:
22+
- "8.0"
23+
- "8.1"
24+
dependencies:
25+
- "highest"
26+
optional-dependencies:
27+
- true
28+
- false
29+
include:
30+
- php-version: "8.0"
31+
dependencies: "lowest"
32+
optional-dependencies: false
33+
- php-version: "8.0"
34+
dependencies: "lowest"
35+
optional-dependencies: true
36+
37+
steps:
38+
- name: "Checkout"
39+
uses: "actions/checkout@v2"
40+
with:
41+
fetch-depth: 2
42+
43+
- name: "Install PHP"
44+
uses: "shivammathur/setup-php@v2"
45+
with:
46+
php-version: "${{ matrix.php-version }}"
47+
coverage: "pcov"
48+
ini-values: "zend.assertions=1"
49+
extensions: "pdo_mysql"
50+
51+
- name: "Install dependencies with Composer"
52+
uses: "ramsey/composer-install@v1"
53+
if: "! startsWith(matrix.php-version, '8')"
54+
with:
55+
dependency-versions: "${{ matrix.dependencies }}"
56+
composer-options: "--prefer-dist --no-suggest"
57+
58+
- name: "Install dependencies with Composer (--ignore-platform-req=php)"
59+
uses: "ramsey/composer-install@v1"
60+
if: "startsWith(matrix.php-version, '8')"
61+
with:
62+
dependency-versions: "${{ matrix.dependencies }}"
63+
composer-options: "--prefer-dist --no-suggest --ignore-platform-req=php"
64+
65+
- name: "Run PHPUnit"
66+
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"
67+
68+
- name: "Upload coverage file"
69+
uses: "actions/upload-artifact@v2"
70+
with:
71+
name: "phpunit-${{ matrix.php-version }}-${{ matrix.dependencies }}-${{ matrix.dbal-version }}.coverage"
72+
path: "coverage.xml"
73+
74+
upload_coverage:
75+
name: "Upload coverage to Codecov"
76+
runs-on: "ubuntu-20.04"
77+
needs:
78+
- "phpunit"
79+
80+
steps:
81+
- name: "Checkout"
82+
uses: "actions/checkout@v2"
83+
with:
84+
fetch-depth: 2
85+
86+
- name: "Download coverage files"
87+
uses: "actions/download-artifact@v2"
88+
with:
89+
path: "reports"
90+
91+
- name: "Upload to Codecov"
92+
uses: "codecov/codecov-action@v2"
93+
with:
94+
directory: "reports"

.github/workflows/php.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PHP Composer
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Validate composer.json and composer.lock
18+
run: composer validate --strict
19+
20+
- name: Cache Composer packages
21+
id: composer-cache
22+
uses: actions/cache@v2
23+
with:
24+
path: vendor
25+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-php-
28+
29+
- name: Install dependencies
30+
run: composer install --prefer-dist --no-progress
31+
32+
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
33+
# Docs: https://getcomposer.org/doc/articles/scripts.md
34+
35+
# - name: Run test suite
36+
# run: composer run-script test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
/vendor/
22
/composer.lock
3+
/.idea/
4+
/.phpcs-cache
5+
/.phpunit.cache/
6+
/coverage/

README.md

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ re-run my fixtures at any time. I want the data my fixtures populate
1111
to be stored with my fixtures and I want to reference fixture values
1212
though class constants within my code.
1313

14-
For instance, to validate a user has an ACL resource the code may
14+
For instance, to validate a user has an ACL role the code may
1515
read:
1616

1717
```php
18-
$acl->has($user, 'admin');
18+
$acl->hasRole($user, 'admin');
1919
```
2020

2121
but this use of strings in the code does not read well and may be
@@ -24,10 +24,114 @@ error-prone. Instead of the above, I want my code to read
2424
```php
2525
use App\ORM\Fixture\RoleFixture;
2626

27-
$acl->has($user, RoleFixture::admin);
27+
$acl->hasRole($user, RoleFixture::admin);
2828
```
2929

3030
This pattern is not possible with seed data because seed data does
3131
not have namespaces. So, this repository exists not only as an
32-
alternative to Laravel seed data, but as an namespaced-integrated
32+
alternative to Laravel seed data, but as a namespaced-integrated
3333
tool for static database data.
34+
35+
36+
Installation
37+
------------
38+
39+
Run the following to install this library using [Composer](https://getcomposer.org/):
40+
41+
```bash
42+
composer require api-skeletons/laravel-doctrine-data-fixtures
43+
```
44+
45+
A `doctrine-data-fixtures.php` configuration file is required. Publish the included config to your project:
46+
47+
```sh
48+
php artisan vendor:publish --tag=config
49+
```
50+
51+
52+
Configuration
53+
-------------
54+
55+
Doctrine MongoDB, ORM and PHPCR are supported. See the configuration file for details.
56+
57+
This example assumes `laravel-doctrine/orm` is installed and you'll be using fixtures
58+
for ORM data:
59+
60+
```php
61+
return [
62+
'default' => [ // This is the group name
63+
'entityManager' => EntityManager::class,
64+
'executor' => ORMExecutor::class,
65+
'purger' => ORMPurger::class,
66+
'fixtures' => [
67+
Fixture1::class,
68+
Fixture2::class,
69+
],
70+
],
71+
];
72+
```
73+
74+
### Fixture Groups
75+
76+
Modeled from [api-skeletons/doctrine-data-fixture](https://github.com/API-Skeletons/doctrine-data-fixture)
77+
for Laminas, fixtures are organized into groups. This organization allows
78+
fixtures for specific modules, development faker data, different entity
79+
managers, and so on.
80+
81+
82+
Use
83+
---
84+
85+
### List Fixtures
86+
87+
List all groups or list all fixtures for a group.
88+
89+
```sh
90+
php artisan doctrine:data-fixtures:list [<group>]
91+
```
92+
93+
### Executing Fixture Group through Artisan command
94+
---------------------------------------------------
95+
96+
```sh
97+
php artisan doctrine:data-fixtures:import <group> [--purge-with-truncate] [--do-not-append]
98+
```
99+
100+
The `<group>` is required.
101+
102+
Append is the default option. This is inversed with --do-not-append
103+
104+
Options:
105+
106+
`--purge-with-truncate` if specified will purge the object manager's tables before
107+
running fixtures for the ORMPurger only.
108+
109+
`--do-not-append` will delete all data in the database before running fixtures.
110+
111+
112+
Executing Fixture Group from code
113+
---------------------------------
114+
115+
For unit testing or other times you must run your fixtures from within code,
116+
follow this example:
117+
118+
```php
119+
$config = $application['config']['doctrine-data-fixtures.' . $groupName];
120+
121+
$objectManager = $application->get($config['objectManager']);
122+
$loader = $application->get($config['loader']);
123+
$purger = $application->get($config['purger']);
124+
125+
foreach ($config['fixtures'] as $fixture) {
126+
$loader->addFixture($fixture);
127+
}
128+
129+
$executor->execute($loader->getFixtures());
130+
```
131+
132+
133+
Doctrine data-fixtures
134+
----------------------
135+
136+
Be sure to read the documentation on the parent library
137+
[doctrine/data-fixtures](https://github.com/doctrine/data-fixtures)

cli-config.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
use Doctrine\ORM\Tools\Console\ConsoleRunner;
3+
use Doctrine\ORM\Tools\Setup;
4+
use Doctrine\ORM\EntityManager;
5+
6+
require_once __DIR__ . '/vendor/autoload.php';
7+
8+
// Create a simple "default" Doctrine ORM configuration for Annotations
9+
$config = Setup::createXMLMetadataConfiguration(array(__DIR__ . "/test/config"), $isDevMode = true);
10+
11+
// database configuration parameters
12+
$conn = array(
13+
'driver' => 'pdo_sqlite',
14+
'dbname' => ':memory:',
15+
);
16+
17+
// obtaining the entity manager
18+
$entityManager = EntityManager::create($conn, $config);
19+
20+
return ConsoleRunner::createHelperSet($entityManager);

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
"laravel/framework": "^8.82"
99
},
1010
"require-dev": {
11-
"phpunit/phpunit": "^9.5"
11+
"phpunit/phpunit": "^9.5",
12+
"doctrine/coding-standard": "^9.0",
13+
"laravel-doctrine/orm": "^1.7",
14+
"orchestra/testbench": "^6.24"
1215
},
1316
"license": "MIT",
1417
"autoload": {
1518
"psr-4": {
16-
"ApiSkeletons\\LaravelDoctrineDataFixtures\\": "src/"
19+
"ApiSkeletons\\Laravel\\Doctrine\\DataFixtures\\": "src/"
20+
}
21+
},
22+
"autoload-dev": {
23+
"psr-4": {
24+
"ApiSkeletonsTest\\Laravel\\Doctrine\\DataFixtures\\": "test/"
1725
}
1826
},
1927
"authors": [

config/doctrine-data-fixtures.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* In the default values listed below, ORM fixtures are configured. You may
5+
* configure other Doctrine fixture group types:
6+
*
7+
* ORMExecutor | PHPCRExecutor | MongoDBExecutor
8+
* ORMPurger | PHPCRPurger | MongoDBPurger
9+
*/
10+
11+
return [
12+
'default' => [ // Group name
13+
'objectManager' => 'Doctrine\ORM\EntityManager',
14+
'executor' => \Doctrine\Common\DataFixtures\Executor\ORMExecutor::class,
15+
'purger' => \Doctrine\Common\DataFixtures\Purger\ORMPurger::class,
16+
'fixtures' => [
17+
// The order of fixtures in this list is not the order in which
18+
// they will be executed. See
19+
// https://github.com/doctrine/data-fixtures#fixture-ordering
20+
/**
21+
Fixture1::class,
22+
Fixture2::class,
23+
*/
24+
],
25+
],
26+
];

phpcs.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="."/>
4+
<arg name="extensions" value="php"/>
5+
<arg name="parallel" value="80"/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
9+
<!-- Ignore warnings, show progress of the run and show sniff names -->
10+
<arg value="nps"/>
11+
12+
<!-- Directories to be checked -->
13+
<file>src</file>
14+
15+
<exclude-pattern>src/Entity/*</exclude-pattern>
16+
17+
<!-- Include full Doctrine Coding Standard -->
18+
<rule ref="Doctrine">
19+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
20+
</rule>
21+
</ruleset>

0 commit comments

Comments
 (0)