Skip to content

Commit f66b11d

Browse files
author
Oliver Klee
committed
[FEATURE] Add the Symfony console and the public web/ directory
Note: The console and the web directory will only be added if this project is the project root (i.e., usually when developing the package), not if is a requirement of the base-distribution package (or any other package). Also add the CI steps and autoloading for the new code.
1 parent 1c0b617 commit f66b11d

File tree

7 files changed

+204
-10
lines changed

7 files changed

+204
-10
lines changed

.github/CONTRIBUTING.md

+33-6
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,51 @@ have a chance of keeping on top of things:
7070

7171
## Unit-test your changes
7272

73-
Please cover all changes with unit tests and make sure that your code does not
74-
break any existing tests. We will only merge pull request that include full
73+
Please cover all changes with automatic tests and make sure that your code does
74+
not break any existing tests. We will only merge pull request that include full
7575
code coverage of the fixed bugs and the new features.
7676

77-
To run the existing PHPUnit tests, run this command:
77+
### Running the integration tests
7878

79-
vendor/bin/phpunit Tests/
79+
For being able to run the integration tests, you will need a local MySQL
80+
database and a user with access permissions to that database.
81+
82+
After you have created the database and the user, please import the database
83+
schema once. Assuming that your database is named `phplist_test`, the user is
84+
named `phplist`, and the password is `batterystaple`, the command looks like
85+
this:
86+
87+
mysql -u phplist_test --password=batterystaple phplist_test < vendor/phplist/phplist4-core/Database/Schema.sql
88+
89+
When running the integration tests, you will need to specify the database name
90+
and access credentials on the command line (in the same line):
91+
92+
PHPLIST_DATABASE_NAME=phplist_test PHPLIST_DATABASE_USER=phplist PHPLIST_DATABASE_PASSWORD=batterystaple vendor/bin/phpunit -c Configuration/PHPUnit/phpunit.xml Tests/Integration/
8093

8194

8295
## Coding Style
8396

97+
Please make your code clean, well-readable and easy to understand.
98+
8499
Please use the same coding style ([PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md))
85100
as the rest of the code. Indentation for all files is four spaces.
86101

87102
We will only merge pull requests that follow the project's coding style.
88103

89104
Please check your code with the provided PHP_CodeSniffer standard:
90105

91-
vendor/bin/phpcs --standard=PSR2 Classes/ Tests/
106+
vendor/bin/phpcs --standard=vendor/phplist/phplist4-core/Configuration/PhpCodeSniffer/ Classes/ Tests/
92107

93-
Please make your code clean, well-readable and easy to understand.
108+
Please also check the code structure using PHPMD:
109+
110+
vendor/bin/phpmd Classes/ text vendor/phplist/phplist4-core/Configuration/PHPMD/rules.xml
111+
112+
And also please run the static code analysis:
113+
114+
vendor/bin/phpstan analyse -l 5 Classes/ Tests/
115+
116+
You can also run all code style checks using one long line from a bash shell:
117+
find Classes/ Tests/ -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l && vendor/bin/phpstan analyse -l 5 Classes/ Tests/ && vendor/bin/phpmd Classes/ text vendor/phplist/phplist4-core/Configuration/PHPMD/rules.xml && vendor/bin/phpcs --standard=vendor/phplist/phplist4-core/Configuration/PhpCodeSniffer/ Classes/ Tests/
118+
119+
This will execute all tests except for the unit tests and the integration
120+
tests.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/.idea/
44
/.project
55
/.webprj
6+
/bin/
67
/composer.lock
78
/nbproject
89
/vendor/
10+
/web/

.travis.yml

+36-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ matrix:
88
services:
99
- mysql
1010

11+
env:
12+
global:
13+
- PHPLIST_DATABASE_NAME=phplist
14+
- PHPLIST_DATABASE_USER=travis
15+
- PHPLIST_DATABASE_PASSWORD=''
16+
1117
sudo: false
1218
cache:
1319
directories:
@@ -16,12 +22,40 @@ cache:
1622

1723
before_install:
1824
- phpenv config-rm xdebug.ini
19-
- mysql -e 'CREATE DATABASE phplist;'
2025

2126
install:
2227
- composer install
2328

29+
before_script:
30+
- >
31+
echo;
32+
echo "Creating the database and importing the database schema";
33+
mysql -e "CREATE DATABASE ${PHPLIST_DATABASE_NAME};";
34+
mysql -u root -e "GRANT ALL ON ${PHPLIST_DATABASE_NAME}.* TO ${PHPLIST_DATABASE_USER}@'%';";
35+
mysql ${PHPLIST_DATABASE_NAME} < vendor/phplist/phplist4-core/Database/Schema.sql;
36+
2437
script:
2538
- >
2639
echo;
27-
echo "Nothing to do yet.";
40+
echo "Linting all PHP files";
41+
find Classes/ Tests/ -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l;
42+
43+
- >
44+
echo;
45+
echo "Running the integration tests";
46+
vendor/bin/phpunit -c Configuration/PHPUnit/phpunit.xml Tests/Integration/;
47+
48+
- >
49+
echo;
50+
echo "Running the static analysis";
51+
vendor/bin/phpstan analyse -l 5 Classes/ Tests/;
52+
53+
- >
54+
echo;
55+
echo "Running PHPMD";
56+
vendor/bin/phpmd Classes/ text vendor/phplist/phplist4-core/Configuration/PHPMD/rules.xml;
57+
58+
- >
59+
echo;
60+
echo "Running PHP_CodeSniffer";
61+
vendor/bin/phpcs --standard=vendor/phplist/phplist4-core/Configuration/PhpCodeSniffer/ Classes/ Tests/;

Classes/.gitkeep

Whitespace-only changes.

Configuration/PHPUnit/phpunit.xml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
bootstrap="../../vendor/autoload.php"
9+
>
10+
<php>
11+
<ini name="error_reporting" value="-1"/>
12+
<server name="KERNEL_CLASS" value="PhpList\PhpList4\Core\ApplicationKernel"/>
13+
</php>
14+
</phpunit>
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PhpList\WebFrontend\Tests\Integration\Composer;
5+
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* Testcase.
10+
*
11+
* @author Oliver Klee <[email protected]>
12+
*/
13+
class ScriptsTest extends TestCase
14+
{
15+
/**
16+
* @test
17+
*/
18+
public function webDirectoryHasBeenCreated()
19+
{
20+
self::assertDirectoryExists($this->getAbsoluteWebDirectoryPath());
21+
}
22+
23+
/**
24+
* @return string
25+
*/
26+
private function getAbsoluteWebDirectoryPath(): string
27+
{
28+
return dirname(__DIR__, 3) . '/web/';
29+
}
30+
31+
/**
32+
* @return string[][]
33+
*/
34+
public function webDirectoryFilesDataProvider(): array
35+
{
36+
return [
37+
'production entry point' => ['app.php'],
38+
'development entry point' => ['app_dev.php'],
39+
'testing entry point' => ['app_test.php'],
40+
'.htaccess' => ['.htaccess'],
41+
];
42+
}
43+
44+
/**
45+
* @test
46+
* @param string $fileName
47+
* @dataProvider webDirectoryFilesDataProvider
48+
*/
49+
public function webDirectoryFilesExist(string $fileName)
50+
{
51+
self::assertFileExists($this->getAbsoluteWebDirectoryPath() . $fileName);
52+
}
53+
54+
/**
55+
* @test
56+
*/
57+
public function binariesDirectoryHasBeenCreated()
58+
{
59+
self::assertDirectoryExists($this->getAbsoluteBinariesDirectoryPath());
60+
}
61+
62+
/**
63+
* @return string
64+
*/
65+
private function getAbsoluteBinariesDirectoryPath(): string
66+
{
67+
return dirname(__DIR__, 3) . '/bin/';
68+
}
69+
70+
/**
71+
* @return string[][]
72+
*/
73+
public function binariesDataProvider(): array
74+
{
75+
return [
76+
'Symfony console' => ['console'],
77+
];
78+
}
79+
80+
/**
81+
* @test
82+
* @param string $fileName
83+
* @dataProvider binariesDataProvider
84+
*/
85+
public function binariesExist(string $fileName)
86+
{
87+
self::assertFileExists($this->getAbsoluteBinariesDirectoryPath() . $fileName);
88+
}
89+
}

composer.json

+30-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,41 @@
3131
"roave/security-advisories": "dev-master"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^6.1",
35-
"squizlabs/php_codesniffer": "^3.0"
34+
"phpunit/phpunit": "^6.2.2",
35+
"squizlabs/php_codesniffer": "^3.0.1",
36+
"phpstan/phpstan": "^0.7.0",
37+
"phpmd/phpmd": "^2.6.0"
3638
},
3739
"autoload": {
3840
"psr-4": {
41+
"PhpList\\WebFrontend\\": "Classes/"
3942
}
4043
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"PhpList\\WebFrontend\\Tests\\": "Tests/"
47+
}
48+
},
49+
"scripts": {
50+
"binaries": [
51+
"PhpList\\PhpList4\\Composer\\ScriptHandler::createBinaries"
52+
],
53+
"document-root": [
54+
"PhpList\\PhpList4\\Composer\\ScriptHandler::createPublicWebDirectory"
55+
],
56+
"post-install-cmd": [
57+
"@binaries",
58+
"@document-root"
59+
],
60+
"post-update-cmd": [
61+
"@binaries",
62+
"@document-root"
63+
],
64+
"post-create-project-cmd": [
65+
"@binaries",
66+
"@document-root"
67+
]
68+
},
4169
"extra": {
4270
"branch-alias": {
4371
"dev-master": "4.0.x-dev"

0 commit comments

Comments
 (0)