Skip to content

Commit 1ccdf6d

Browse files
authored
Updates symfony example for symfony-demo 1.5 (GoogleCloudPlatform#1033)
1 parent 07d520f commit 1ccdf6d

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

appengine/php72/symfony-framework/src/EventSubscriber/ExceptionSubscriber.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use Google\Cloud\ErrorReporting\Bootstrap;
2424
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
25-
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
25+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
2626
use Symfony\Component\HttpKernel\KernelEvents;
2727

2828
/**
@@ -40,9 +40,9 @@ public static function getSubscribedEvents()
4040
]];
4141
}
4242

43-
public function logException(GetResponseForExceptionEvent $event)
43+
public function logException(ExceptionEvent $event)
4444
{
45-
$exception = $event->getException();
45+
$exception = $event->getThrowable();
4646
Bootstrap::init();
4747
Bootstrap::exceptionHandler($exception);
4848
}

appengine/php72/symfony-framework/test/DeployDoctrineTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
namespace Google\Cloud\Samples\AppEngine\Symfony;
1919

20-
use Google\Cloud\TestUtils\TestTrait;
2120
use PHPUnit\Framework\TestCase;
2221

2322
require_once __DIR__ . '/DeploySymfonyTrait.php';
2423

2524
class DeployDoctrineTest extends TestCase
2625
{
27-
use TestTrait;
2826
use DeploySymfonyTrait;
2927

3028
public static function beforeDeploy()

appengine/php72/symfony-framework/test/DeploySymfonyTrait.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
use Google\Cloud\TestUtils\AppEngineDeploymentTrait;
2121
use Google\Cloud\TestUtils\ExecuteCommandTrait;
2222
use Google\Cloud\TestUtils\FileUtil;
23-
use PhpParser\PrettyPrinter;
24-
use PhpParser\ParserFactory;
25-
use PhpParser\Node;
26-
use PhpParser\Node\Stmt\ClassMethod;
27-
use PhpParser\NodeTraverser;
28-
use PhpParser\NodeVisitorAbstract;
2923

3024
trait DeploySymfonyTrait
3125
{
@@ -35,15 +29,15 @@ trait DeploySymfonyTrait
3529
private static function createSymfonyProject()
3630
{
3731
$tmpDir = sys_get_temp_dir() . '/test-' . FileUtil::randomName(8);
38-
self::setWorkingDirectory($tmpDir);
39-
4032

4133
// install
42-
$demoVersion = 'symfony/symfony-demo:^1.2';
34+
$demoVersion = 'symfony/symfony-demo:^1.5';
4335
$cmd = sprintf('composer create-project %s %s || true', $demoVersion, $tmpDir);
4436
$process = self::createProcess($cmd);
4537
$process->setTimeout(300); // 5 minutes
38+
4639
self::executeProcess($process);
40+
self::setWorkingDirectory($tmpDir);
4741

4842
// move app.yaml for the sample to the new symfony installation
4943
self::copyFiles(['app.yaml'], $tmpDir);
@@ -64,35 +58,43 @@ private static function createSymfonyProject()
6458
private static function updateKernelCacheAndLogDir($projectDir)
6559
{
6660
$kernelFile = $projectDir . '/src/Kernel.php';
67-
$parser = (new ParserFactory)->create(ParserFactory::ONLY_PHP7);
68-
$ast = $parser->parse(file_get_contents($kernelFile));
69-
$newStmts = $parser->parse(<<<'CODE'
70-
71-
if ($this->environment === 'prod') {
72-
return sys_get_temp_dir();
61+
$kernelContents = file_get_contents($kernelFile);
62+
63+
$newCode = <<<'EOF'
64+
65+
public function getCacheDir()
66+
{
67+
if ($this->environment === 'prod') {
68+
return sys_get_temp_dir();
69+
}
70+
return parent::getCacheDir();
71+
}
72+
73+
public function getLogDir()
74+
{
75+
if ($this->environment === 'prod') {
76+
return sys_get_temp_dir();
77+
}
78+
return parent::getLogDir();
79+
}
7380
}
74-
CODE
75-
);
76-
77-
$traverser = new NodeTraverser();
78-
$traverser->addVisitor(new class($newStmts) extends NodeVisitorAbstract {
79-
public function __construct($newStmts)
80-
{
81-
$this->newStmts = $newStmts;
82-
}
83-
84-
public function enterNode(Node $node)
85-
{
86-
if ($node instanceof ClassMethod
87-
&& in_array($node->name, ['getCacheDir', 'getLogDir'])) {
88-
$node->stmts = array_merge($this->newStmts, $node->stmts);
89-
}
90-
}
91-
});
92-
93-
$ast = $traverser->traverse($ast);
94-
$prettyPrinter = new PrettyPrinter\Standard();
95-
file_put_contents($kernelFile, $prettyPrinter->prettyPrintFile($ast));
81+
EOF;
82+
83+
$newContents = preg_replace(
84+
'/^}$/m',
85+
$newCode,
86+
$kernelContents,
87+
1,
88+
$count
89+
);
90+
91+
if ($count != 1) {
92+
throw new \UnexpectedValueException(
93+
'Failed to update Kernel Cache and Log Dir'
94+
);
95+
}
96+
97+
file_put_contents($kernelFile, $newContents);
9698
}
9799

98100
private static function copyFiles(array $files, $dir)

appengine/php72/symfony-framework/test/DeployTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testLogging()
6565
$this->eventuallyConsistentRetryCount = 5;
6666

6767
$logging = new LoggingClient([
68-
'projectId' => self::getProjectId()
68+
'projectId' => self::$projectId
6969
]);
7070

7171
$token = uniqid();
@@ -98,7 +98,7 @@ public function testErrorReporting()
9898
{
9999
$this->eventuallyConsistentRetryCount = 5;
100100
$logging = new LoggingClient([
101-
'projectId' => self::getProjectId()
101+
'projectId' => self::$projectId
102102
]);
103103

104104
$token = uniqid();
@@ -123,7 +123,7 @@ public function testErrorReporting()
123123
$found = true;
124124
}
125125
}
126-
$this->assertTrue($found, 'The log entry was not found');
126+
$this->assertTrue($found, 'The error reporting entry was not found');
127127
});
128128
}
129129
}

0 commit comments

Comments
 (0)