Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow symfony6, update tests for installable set #73

Merged
merged 5 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/vendor/
/var/
!/var/.gitkeep
.phpunit.result.cache

composer.lock
clover.xml
13 changes: 9 additions & 4 deletions Factories/RollbarHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Rollbar\Symfony\RollbarBundle\Factories;

use Psr\Log\LogLevel;
use Rollbar\Monolog\Handler\RollbarHandler;
use Rollbar\Monolog\Handler\RollbarHandler as RollbarHandlerLegacy;
use Monolog\Handler\RollbarHandler;
use Rollbar\Rollbar;
use Rollbar\Symfony\RollbarBundle\DependencyInjection\RollbarExtension;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -52,10 +53,14 @@ public function __construct(ContainerInterface $container)
/**
* Create RollbarHandler
*
* @return RollbarHandler
* @return RollbarHandler|RollbarHandlerLegacy
*/
public function createRollbarHandler(): RollbarHandler
public function createRollbarHandler()
{
return new RollbarHandler(Rollbar::logger(), LogLevel::ERROR);
if (class_exists(RollbarHandler::class)) {
return new RollbarHandler(Rollbar::logger(), LogLevel::ERROR);
}

return new RollbarHandlerLegacy(Rollbar::logger(), LogLevel::ERROR);
}
}
32 changes: 4 additions & 28 deletions Tests/DependencyInjection/RollbarExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ protected function getContainerExtensions(): array
}

/**
* Test config enabled vars.
* Test config vars.
*
* @dataProvider generatorConfigVars
*
* @param string $var
* @param array $expected
*/
public function testConfigEnabledVars(string $var, array $expected): void
public function testConfigVars(string $var, array $expected, array $loadParameters = []): void
{
$this->load();
$this->load($loadParameters);

$param = $this->container->getParameter($var);

foreach ($expected as $key => $value) {
$this->assertEquals($param[$key], $value);
}
Expand All @@ -54,30 +50,10 @@ public function generatorConfigVars(): array
{
return [
['rollbar.config', ['enabled' => true]],
['rollbar.config', ['enabled' => false], ['enabled' => false]],
];
}

/**
* Test config disabled vars.
*
* @dataProvider generatorConfigVars
*
* @expectedException \PHPUnit_Framework_ExpectationFailedException
*
* @param string $var
* @param array $expected
*/
public function testConfigDisabledVars(string $var, array $expected): void
{
$this->load(['enabled' => false]);

$param = $this->container->getParameter($var);

foreach ($expected as $key => $value) {
$this->assertEquals($param[$key], $value);
}
}

/**
* Test alias.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Tests\Fixtures\App;

use Rollbar\Symfony\RollbarBundle\RollbarBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MonologBundle\MonologBundle;
Expand All @@ -8,37 +10,28 @@

class AppKernel extends Kernel
{
public function registerBundles()
public function registerBundles(): array
{
$bundles = [
return [
new FrameworkBundle(),
new MonologBundle(),
new RollbarBundle(),
];

return $bundles;
}

/**
* @return string
*/
public function getRootDir(): string
{
return __DIR__;
}

/**
* @param LoaderInterface $loader
* @throws Exception
* @throws \Exception
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}

/**
* @return string
*/
public function getCacheDir(): string
{
return realpath(__DIR__ . '/../../../') . '/var/' . $this->environment . '/cache';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ parameters:
locale: ~

framework:
test: true
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
resource: "%kernel.project_dir%/config/routing.yml"
strict_requirements: ~
2 changes: 1 addition & 1 deletion Tests/Payload/ErrorItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testInvoke(int $code, string $message, string $file, int $line,

$exception = $data['exception'];
$this->assertEquals($mapped, $exception['class']);
$this->assertContains($message, $exception['message']);
$this->assertStringContainsString($message, $exception['message']);

$this->assertCount(1, $data['frames']);

Expand Down
7 changes: 3 additions & 4 deletions Tests/Payload/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ public function setUp(): void
*/
public function testGetContainer(): void
{
$container = $this->getContainer();
$generator = $this->getGenerator();

$result = $generator->getContainer();

$this->assertEquals($container, $result);
$this->assertInstanceOf(ContainerInterface::class, $result);
}

/**
Expand Down Expand Up @@ -185,7 +184,7 @@ public function testGetExceptionPayload(): void

list($message, $payload) = $generator->getExceptionPayload($exception);

$this->assertContains($msg, $message);
$this->assertStringContainsString($msg, $message);

$this->assertArrayHasKey('body', $payload);
$this->assertArrayHasKey('request', $payload);
Expand Down Expand Up @@ -244,7 +243,7 @@ public function generatorStrangeData(): array
*
* @return ContainerInterface
*/
private function getContainer(): ContainerInterface
protected static function getContainer(): ContainerInterface
{
return static::$container ?? static::$kernel->getContainer();
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Payload/TraceItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function testInvoke(): void

$exception = $data['exception'];
$this->assertEquals(get_class($ex), $exception['class']);
$this->assertContains($msg, $exception['message']);
$this->assertStringContainsString($msg, $exception['message']);

$this->assertGreaterThan(1, count($data['frames']));

$frame = $data['frames'][0];
$this->assertTrue(array_key_exists('filename', $frame));
$this->assertTrue(array_key_exists('lineno', $frame));
$this->assertTrue(array_key_exists('class_name', $frame));
$this->assertArrayHasKey('filename', $frame);
$this->assertArrayHasKey('lineno', $frame);
$this->assertArrayHasKey('class_name', $frame);
}
}
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
"Tests/Fixtures/app/AppKernel.php",
"Tests/Fixtures/ErrorHandler.php"
],
"psr-4": { "Tests\\": "tests/"}
"psr-4": { "Tests\\": "Tests/"}
},
"require": {
"php": ">=7.1",
"rollbar/rollbar": "^2",
"symfony/dependency-injection": "^5.0",
"symfony/config": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/monolog-bundle": "*",
"symfony/serializer": "*",
"rollbar/rollbar": "^2|^3.0",
art-cg marked this conversation as resolved.
Show resolved Hide resolved
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/monolog-bundle": "^3.0",
"symfony/serializer": "^5.4|^6.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"symfony/framework-bundle": "^5.0",
"squizlabs/php_codesniffer": "^2.7",
"matthiasnoback/symfony-dependency-injection-test": "^1.1"
"phpunit/phpunit": "^8.5",
"symfony/framework-bundle": "^5.4|^6.0",
"squizlabs/php_codesniffer": "^3.6",
"matthiasnoback/symfony-dependency-injection-test": "^4.3"
},
"scripts": {
"test": [
Expand Down
14 changes: 8 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="false"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_DIR" value="Tests/Fixtures/app" />
<server name="KERNEL_CLASS" value="AppKernel" />
<server name="APP_ENV" value="test" force="true"/>
<server name="KERNEL_DIR" value="Tests/Fixtures/App" />
<server name="KERNEL_CLASS" value="Tests\Fixtures\App\AppKernel" />
<server name="SHELL_VERBOSITY" value="-1"/>
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
<env name="ROLLBAR_TEST_TOKEN" value="ad865e76e7fb496fab096ac07b1dbabb" />
</php>

<testsuites>
Expand All @@ -25,7 +29,5 @@
<directory>./</directory>
</whitelist>
</filter>
<php>
<env name="ROLLBAR_TEST_TOKEN" value="ad865e76e7fb496fab096ac07b1dbabb" />
</php>

</phpunit>