Skip to content

Commit 5887cb8

Browse files
First basic implementation (#1)
Allows to import a PHP data set within TYPO3 testing framework. Allows to assert a PHP data set within TYPO3 testing framework.
1 parent 150e2b6 commit 5887cb8

24 files changed

+982
-2
lines changed

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Tests export-ignore
2+
.github export-ignore
3+
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
7+
.php-cs-fixer.dist.php export-ignore
8+
phpstan.neon export-ignore
9+
phpunit.xml.dist export-ignore
10+
11+
shell.nix export-ignore

.github/workflows/ci.yaml

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
check-composer:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Install PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: 8.2
19+
coverage: none
20+
tools: composer:v2
21+
env:
22+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Validate composer.json
25+
run: composer validate
26+
27+
php-linting:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
php-version:
32+
- 7.3
33+
- 7.4
34+
- 8.0
35+
- 8.1
36+
- 8.2
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v3
40+
41+
- name: Install PHP
42+
uses: shivammathur/setup-php@v2
43+
with:
44+
php-version: "${{ matrix.php-version }}"
45+
coverage: none
46+
47+
- name: PHP lint
48+
run: "find *.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l"
49+
50+
xml-linting:
51+
runs-on: ubuntu-latest
52+
needs:
53+
- check-composer
54+
steps:
55+
- uses: actions/checkout@v3
56+
57+
- name: Install PHP
58+
uses: shivammathur/setup-php@v2
59+
with:
60+
php-version: "8.2"
61+
coverage: none
62+
tools: composer:v2
63+
env:
64+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
66+
- name: Install xmllint
67+
run: sudo apt-get install libxml2-utils
68+
69+
- name: Install dependencies
70+
run: composer install --prefer-dist --no-progress
71+
72+
- name: PHPUnit configuration file
73+
run: xmllint --schema vendor/phpunit/phpunit/phpunit.xsd --noout phpunit.xml.dist
74+
75+
coding-guideline:
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@v3
79+
80+
- name: Install PHP
81+
uses: shivammathur/setup-php@v2
82+
with:
83+
php-version: "8.1"
84+
coverage: none
85+
tools: composer:v2
86+
env:
87+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Install dependencies
90+
run: composer install --prefer-dist --no-progress
91+
92+
- name: Coding Guideline
93+
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
94+
95+
tests-mysql:
96+
runs-on: ubuntu-latest
97+
needs:
98+
- xml-linting
99+
strategy:
100+
matrix:
101+
include:
102+
- db-version: '5.7'
103+
php-version: '7.3'
104+
typo3-version: '^10.4'
105+
- db-version: '8'
106+
php-version: '7.4'
107+
typo3-version: '^10.4'
108+
- db-version: '8'
109+
php-version: '7.4'
110+
typo3-version: '^11.5'
111+
- db-version: '8'
112+
php-version: '8.0'
113+
typo3-version: '^11.5'
114+
- db-version: '8'
115+
php-version: '8.1'
116+
typo3-version: '^11.5'
117+
- db-version: '8'
118+
php-version: '8.2'
119+
typo3-version: '^11.5'
120+
steps:
121+
- uses: actions/checkout@v3
122+
123+
- name: Install PHP
124+
uses: shivammathur/setup-php@v2
125+
with:
126+
php-version: "${{ matrix.php-version }}"
127+
coverage: none
128+
tools: composer:v2
129+
env:
130+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
132+
- name: Setup MySQL
133+
uses: mirromutth/[email protected]
134+
with:
135+
mysql version: '${{ matrix.db-version }}'
136+
mysql database: 'typo3'
137+
mysql root password: 'root'
138+
139+
- name: Wait for MySQL
140+
run: |
141+
while ! mysqladmin ping --host=127.0.0.1 --password=root --silent; do
142+
sleep 1
143+
done
144+
145+
- name: Install dependencies with expected TYPO3 version
146+
run: composer require --prefer-dist --no-progress "typo3/cms-core:${{ matrix.typo3-version }}"
147+
148+
- name: PHPUnit Tests
149+
run: |-
150+
export typo3DatabaseDriver="pdo_mysql"
151+
export typo3DatabaseName="typo3"
152+
export typo3DatabaseHost="127.0.0.1"
153+
export typo3DatabaseUsername="root"
154+
export typo3DatabasePassword="root"
155+
./vendor/bin/phpunit --testdox
156+
157+
code-quality:
158+
runs-on: ubuntu-latest
159+
strategy:
160+
matrix:
161+
include:
162+
- php-version: '7.3'
163+
typo3-version: '^10.4'
164+
- php-version: '7.4'
165+
typo3-version: '^10.4'
166+
- php-version: '7.4'
167+
typo3-version: '^11.5'
168+
- php-version: '8.0'
169+
typo3-version: '^11.5'
170+
- php-version: '8.1'
171+
typo3-version: '^11.5'
172+
- php-version: '8.2'
173+
typo3-version: '^11.5'
174+
steps:
175+
- uses: actions/checkout@v3
176+
177+
- name: Install PHP
178+
uses: shivammathur/setup-php@v2
179+
with:
180+
php-version: "${{ matrix.php-version }}"
181+
coverage: none
182+
tools: composer:v2
183+
env:
184+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185+
186+
- name: Install dependencies with expected TYPO3 version
187+
run: composer require --prefer-dist --no-progress "typo3/cms-backend:${{ matrix.typo3-version }}" "typo3/cms-core:${{ matrix.typo3-version }}" "typo3/cms-dashboard:${{ matrix.typo3-version }}"
188+
189+
- name: Code Quality (by PHPStan)
190+
run: ./vendor/bin/phpstan analyse

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.Build/
2+
/composer.lock
3+
/vendor/

.php-cs-fixer.dist.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
$finder = (new PhpCsFixer\Finder())
3+
->ignoreVCSIgnored(true)
4+
->in(realpath(__DIR__));
5+
6+
return (new \PhpCsFixer\Config())
7+
->setRiskyAllowed(true)
8+
->setRules([
9+
'@DoctrineAnnotation' => true,
10+
'@PSR2' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
'blank_line_after_opening_tag' => true,
13+
'braces' => ['allow_single_line_closure' => true],
14+
'cast_spaces' => ['space' => 'none'],
15+
'compact_nullable_typehint' => true,
16+
'concat_space' => ['spacing' => 'one'],
17+
'declare_equal_normalize' => ['space' => 'none'],
18+
'dir_constant' => true,
19+
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
20+
'function_typehint_space' => true,
21+
'lowercase_cast' => true,
22+
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
23+
'modernize_strpos' => true,
24+
'modernize_types_casting' => true,
25+
'native_function_casing' => true,
26+
'new_with_braces' => true,
27+
'no_alias_functions' => true,
28+
'no_blank_lines_after_phpdoc' => true,
29+
'no_empty_phpdoc' => true,
30+
'no_empty_statement' => true,
31+
'no_extra_blank_lines' => true,
32+
'no_leading_import_slash' => true,
33+
'no_leading_namespace_whitespace' => true,
34+
'no_null_property_initialization' => true,
35+
'no_short_bool_cast' => true,
36+
'no_singleline_whitespace_before_semicolons' => true,
37+
'no_superfluous_elseif' => true,
38+
'no_trailing_comma_in_singleline_array' => true,
39+
'no_unneeded_control_parentheses' => true,
40+
'no_unused_imports' => true,
41+
'no_useless_else' => true,
42+
'no_whitespace_in_blank_line' => true,
43+
'ordered_imports' => true,
44+
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
45+
'php_unit_mock_short_will_return' => true,
46+
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
47+
'phpdoc_no_access' => true,
48+
'phpdoc_no_empty_return' => true,
49+
'phpdoc_no_package' => true,
50+
'phpdoc_scalar' => true,
51+
'phpdoc_trim' => true,
52+
'phpdoc_types' => true,
53+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
54+
'return_type_declaration' => ['space_before' => 'none'],
55+
'single_quote' => true,
56+
'single_line_comment_style' => ['comment_types' => ['hash']],
57+
'single_trait_insert_per_statement' => true,
58+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
59+
'whitespace_after_comma_in_array' => true,
60+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
61+
])
62+
->setFinder($finder);

Classes/PhpDataSet.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* Copyright (C) 2023 Daniel Siepmann <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* as published by the Free Software Foundation; either version 2
11+
* of the License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21+
* 02110-1301, USA.
22+
*/
23+
24+
namespace Codappix\Typo3PhpDatasets;
25+
26+
use TYPO3\CMS\Core\Database\ConnectionPool;
27+
use TYPO3\CMS\Core\Utility\GeneralUtility;
28+
29+
class PhpDataSet
30+
{
31+
public function import(array $dataSet): void
32+
{
33+
foreach ($dataSet as $tableName => $records) {
34+
$connection = $this->getConnectionPool()->getConnectionForTable($tableName);
35+
$tableDetails = $connection->getSchemaManager()->listTableDetails($tableName);
36+
37+
foreach ($records as $record) {
38+
$types = [];
39+
foreach (array_keys($record) as $columnName) {
40+
$types[] = $tableDetails->getColumn((string)$columnName)->getType()->getBindingType();
41+
}
42+
43+
$connection->insert($tableName, $record, $types);
44+
}
45+
}
46+
}
47+
48+
private function getConnectionPool(): ConnectionPool
49+
{
50+
return GeneralUtility::makeInstance(ConnectionPool::class);
51+
}
52+
}

0 commit comments

Comments
 (0)