Skip to content

Commit 0dc4bf2

Browse files
author
Oliver Klee
committed
[FEATURE] Development and testing web server
The server can be started using this command: bin/console server:run Also document the use of the different environments. Fixes #25
1 parent df1288d commit 0dc4bf2

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

Classes/Core/ApplicationKernel.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use PhpList\PhpList4\ApplicationBundle\PhpListApplicationBundle;
77
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
8+
use Symfony\Bundle\WebServerBundle\WebServerBundle;
89
use Symfony\Component\Config\Loader\LoaderInterface;
910
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
1011
use Symfony\Component\HttpKernel\Kernel;
@@ -31,6 +32,10 @@ public function registerBundles(): array
3132
new PhpListApplicationBundle(),
3233
];
3334

35+
if ($this->shouldHaveDevelopmentBundles()) {
36+
$bundles[] = new WebServerBundle();
37+
}
38+
3439
// This will later be changed so that the REST API package can register itself to the core.
3540
if ($this->isRestBundleInstalled()) {
3641
$className = $this->getRestBundleClassName();
@@ -123,4 +128,12 @@ private function getRestBundleClassName(): string
123128
{
124129
return 'PhpList\\RestBundle\\PhpListRestBundle';
125130
}
131+
132+
/**
133+
* @return bool
134+
*/
135+
private function shouldHaveDevelopmentBundles(): bool
136+
{
137+
return $this->environment !== Environment::PRODUCTION;
138+
}
126139
}

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ this code.
5858
a [description of the domain entities](Documentation/DomainModel/Entities.md)
5959

6060

61+
## Running the web server
62+
63+
The phpList application is configured that the built-in PHP web server can run
64+
in development and testing mode, while Apache can run in production mode.
65+
66+
### Development
67+
68+
For running the application in development mode using the build-in PHP server,
69+
use this command:
70+
71+
bin/console server:run
72+
73+
The server will then listen on `http://127.0.0.1:8000` (or, if port 8000 is
74+
already in use, on the next free port after 8000).
75+
76+
You can stop the server with CTRL + C.
77+
78+
### Testing
79+
80+
To run the server in testing mode (which normally will only be needed for the
81+
automated tests, provide the `--dev` option:
82+
83+
bin/console server:run --env=test
84+
85+
### Production
86+
87+
For documentation on running the application in production mode using Apache,
88+
please see the
89+
[phpList base distribution README](https://github.com/phpList/base-distribution).
90+
91+
6192
## Changing the database schema
6293

6394
Any changes to the database schema must always be done both in phpList 3 and
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace PhpList\PhpList4\Tests\Support\Traits;
5+
6+
/**
7+
* This trait provides the assertContainsInstanceOf method.
8+
*
9+
* @author Oliver Klee <[email protected]>
10+
*/
11+
trait ContainsInstanceAssertionTrait
12+
{
13+
/**
14+
* @param string $className
15+
* @param array $haystack
16+
* @param string $message
17+
*
18+
* @return void
19+
*/
20+
public static function assertContainsInstanceOf(string $className, array $haystack, string $message = '')
21+
{
22+
$found = false;
23+
foreach ($haystack as $element) {
24+
if (is_object($element) && $element instanceof $className) {
25+
$found = true;
26+
break;
27+
}
28+
}
29+
30+
$defaultMessage = 'Failed asserting that an array contains an instance of ' . $className;
31+
self::assertTrue($found, $message ?: $defaultMessage);
32+
}
33+
}

Tests/Unit/Core/ApplicationKernelTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
namespace PhpList\PhpList4\Tests\Unit\Core;
55

6+
use PhpList\PhpList4\ApplicationBundle\PhpListApplicationBundle;
67
use PhpList\PhpList4\Core\ApplicationKernel;
78
use PhpList\PhpList4\Core\Bootstrap;
89
use PhpList\PhpList4\Core\Environment;
10+
use PhpList\PhpList4\Tests\Support\Traits\ContainsInstanceAssertionTrait;
911
use PHPUnit\Framework\TestCase;
12+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\WebServerBundle\WebServerBundle;
14+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
1015
use Symfony\Component\HttpKernel\Kernel;
1116

1217
/**
@@ -16,6 +21,8 @@
1621
*/
1722
class ApplicationKernelTest extends TestCase
1823
{
24+
use ContainsInstanceAssertionTrait;
25+
1926
/**
2027
* @var ApplicationKernel
2128
*/
@@ -38,4 +45,38 @@ public function isKernelInstance()
3845
{
3946
self::assertInstanceOf(Kernel::class, $this->subject);
4047
}
48+
49+
/**
50+
* @test
51+
*/
52+
public function registerBundlesReturnsBundlesOnly()
53+
{
54+
$bundles = $this->subject->registerBundles();
55+
56+
self::assertContainsOnlyInstancesOf(BundleInterface::class, $bundles);
57+
}
58+
59+
/**
60+
* @return string[][]
61+
*/
62+
public function requiredBundlesDataProvider(): array
63+
{
64+
return [
65+
'framework' => [FrameworkBundle::class],
66+
'phpList default bundle' => [PhpListApplicationBundle::class],
67+
'web server' => [WebServerBundle::class],
68+
];
69+
}
70+
71+
/**
72+
* @test
73+
* @param string $className
74+
* @dataProvider requiredBundlesDataProvider
75+
*/
76+
public function registerBundlesHasAllRequiredBundles(string $className)
77+
{
78+
$bundles = $this->subject->registerBundles();
79+
80+
self::assertContainsInstanceOf($className, $bundles);
81+
}
4182
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
"doctrine/orm": "^2.5.6",
3232
"symfony/symfony": "^3.3.2",
33+
"symfony/monolog-bundle": "^3.1.0",
3334
"sensio/framework-extra-bundle": "^3.0.26"
3435
},
3536
"require-dev": {

0 commit comments

Comments
 (0)