Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 7d58c5b

Browse files
committed
Preparing functional tests
1 parent d0014ab commit 7d58c5b

File tree

10 files changed

+359
-73
lines changed

10 files changed

+359
-73
lines changed

composer.lock

Lines changed: 16 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<whitelist>
2626
<directory>./</directory>
2727
<exclude>
28-
<directory>./Tests</directory>
28+
<directory>./tests</directory>
2929
<directory>./vendor</directory>
3030
</exclude>
3131
</whitelist>

src/Response/CacheableResponse.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
<?php
2+
23
/**
3-
* Created by PhpStorm.
4-
* User: Geolim4
5-
* Date: 12/05/2018
6-
* Time: 02:18
4+
*
5+
* This file is part of phpFastCache.
6+
*
7+
* @license MIT License (MIT)
8+
*
9+
* For full copyright and license information, please see the docs/CREDITS.txt file.
10+
*
11+
* @author Georges.L (Geolim4) <contact@geolim4.com>
12+
*
713
*/
14+
declare(strict_types=1);
815

916
namespace Phpfastcache\Bundle\Response;
1017

@@ -60,6 +67,10 @@ public function getResponse(string $cacheKey, $expiresAfter = null, callable $ca
6067
if($response instanceof Response){
6168
$cacheItem->expiresAfter($expiresAfter);
6269

70+
/**
71+
* Alter response header to set
72+
* cache/expiration directives
73+
*/
6374
$response->setExpires($cacheItem->getExpirationDate());
6475
$response->setSharedMaxAge($cacheItem->getTtl());
6576
$response->headers->addCacheControlDirective('must-revalidate', true);

tests/Functional/App/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/var/
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/**
4+
*
5+
* This file is part of phpFastCache.
6+
*
7+
* @license MIT License (MIT)
8+
*
9+
* For full copyright and license information, please see the docs/CREDITS.txt file.
10+
*
11+
* @author Georges.L (Geolim4) <contact@geolim4.com>
12+
* @author PastisD https://github.com/PastisD
13+
*
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
namespace Phpfastcache\Bundle\Tests\Functional\App\Controller;
19+
20+
use Phpfastcache\Bundle\Service\Phpfastcache;
21+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
22+
use Symfony\Component\HttpFoundation\JsonResponse;
23+
use Symfony\Component\HttpFoundation\Request;
24+
use Symfony\Component\HttpFoundation\Response;
25+
26+
/**
27+
* Class CacheController
28+
* @package Phpfastcache\Bundle\Tests\Functional\App\Controller
29+
*/
30+
class CacheController extends AbstractController
31+
{
32+
33+
/**
34+
* @param \Symfony\Component\HttpFoundation\Request $request
35+
* @param \Phpfastcache\Bundle\Service\Phpfastcache $phpfastcache
36+
* @return Response
37+
*/
38+
public function index(Request $request, Phpfastcache $phpfastcache)
39+
{
40+
return JsonResponse::create(['result' => 'ok']);
41+
}
42+
43+
/**
44+
* @param \Symfony\Component\HttpFoundation\Request $request
45+
* @param \Phpfastcache\Bundle\Service\Phpfastcache $phpfastcache
46+
* @return Response
47+
*/
48+
public function cacheMiss(Request $request, Phpfastcache $phpfastcache)
49+
{
50+
return JsonResponse::create(['result' => 'ok']);
51+
}
52+
53+
/**
54+
* @param \Symfony\Component\HttpFoundation\Request $request
55+
* @param \Phpfastcache\Bundle\Service\Phpfastcache $phpfastcache
56+
* @return Response
57+
*/
58+
public function cacheHit(Request $request, Phpfastcache $phpfastcache)
59+
{
60+
return JsonResponse::create(['result' => 'ok']);
61+
}
62+
}

tests/Functional/App/Kernel.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/**
4+
*
5+
* This file is part of phpFastCache.
6+
*
7+
* @license MIT License (MIT)
8+
*
9+
* For full copyright and license information, please see the docs/CREDITS.txt file.
10+
*
11+
* @author Georges.L (Geolim4) <contact@geolim4.com>
12+
* @author PastisD https://github.com/PastisD
13+
*
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
namespace Phpfastcache\Bundle\Tests\Functional\App;
19+
20+
use Phpfastcache\Bundle\Tests\Functional\App\Controller\CacheController;
21+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
22+
use Symfony\Component\Config\Loader\LoaderInterface;
23+
use Symfony\Component\DependencyInjection\ContainerBuilder;
24+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
25+
use Symfony\Component\Routing\RouteCollectionBuilder;
26+
27+
/**
28+
* Class Kernel
29+
* @package Phpfastcache\Bundle\Tests\Functional\App
30+
*/
31+
class Kernel extends BaseKernel
32+
{
33+
use MicroKernelTrait;
34+
35+
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
36+
37+
/**
38+
* @return array|iterable|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
39+
*/
40+
public function registerBundles()
41+
{
42+
return [
43+
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
44+
new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(),
45+
new \Symfony\Bundle\TwigBundle\TwigBundle(),
46+
new \Phpfastcache\Bundle\PhpfastcacheBundle(),
47+
];
48+
}
49+
50+
/**
51+
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
52+
* @param \Symfony\Component\Config\Loader\LoaderInterface $loader
53+
* @throws \Exception
54+
*/
55+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
56+
{
57+
$loader->load(__DIR__ . '/config.yaml');
58+
}
59+
60+
/**
61+
* @param \Symfony\Component\Routing\RouteCollectionBuilder $routes
62+
*/
63+
protected function configureRoutes(RouteCollectionBuilder $routes)
64+
{
65+
$routes->add('/', CacheController::class . ':index');
66+
$routes->add('/cache/miss', CacheController::class . ':cacheMiss');
67+
$routes->add('/cache/hit', CacheController::class . ':cacheHit');
68+
}
69+
70+
/**
71+
* @return string
72+
*/
73+
public function getRootDir()
74+
{
75+
return __DIR__ . '/var';
76+
}
77+
78+
/**
79+
* @return string
80+
*/
81+
public function getProjectDir()
82+
{
83+
return __DIR__;
84+
}
85+
}

tests/Functional/App/config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
imports:
2+
- { resource: 'services.yaml' }
3+
4+
framework:
5+
secret: test
6+
test: ~
7+
default_locale: en
8+
profiler: { collect: true }
9+
session:
10+
storage_id: session.storage.mock_file
11+
12+
web_profiler:
13+
toolbar: false
14+
intercept_redirects: false

tests/Functional/App/services.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
_defaults:
3+
public: false
4+
autoconfigure: true
5+
autowire: true
6+
7+
logger:
8+
class: Psr\Log\NullLogger
9+
10+
Phpfastcache\Bundle\Tests\Functional\App\Controller\:
11+
resource: './Controller'
12+
public: true
13+
tags: ['controller.service_arguments']

0 commit comments

Comments
 (0)