Permalink
Browse files

moved component and bridge unit tests to the src/ directory

This is the first step to make each Symfony Component and Bridge self-contained.
  • Loading branch information...
1 parent 8df31a4 commit 5793297162701ea4f83fac5b81d38f475856dea2 @fabpot fabpot committed Mar 28, 2012
Showing with 133 additions and 2 deletions.
  1. +9 −2 README.md
  2. +61 −0 Tests/Processor/WebProcessorTest.php
  3. +34 −0 Tests/bootstrap.php
  4. +29 −0 phpunit.xml.dist
View
@@ -6,6 +6,13 @@ Provides integration for Monolog with various Symfony2 components.
Resources
---------
-Unit tests:
+You can run the unit tests with the following command:
-https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Bridge/Monolog
+ phpunit -c src/Symfony/Bridge/Monolog/
+
+If you also want to run the unit tests that depend on other Symfony
+Components, declare the following environment variables before running
+PHPUnit:
+
+ export MONOLOG=../path/to/Monolog
+ export SYMFONY_HTTP_FOUNDATION=../path/to/HttpFoundation
@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\Monolog\Tests\Processor;
+
+use Monolog\Logger;
+use Symfony\Bridge\Monolog\Processor\WebProcessor;
+use Symfony\Component\HttpFoundation\Request;
+
+class WebProcessorTest extends \PHPUnit_Framework_TestCase
+{
+ protected function setUp()
+ {
+ if (!class_exists('Monolog\\Logger')) {
+ $this->markTestSkipped('Monolog is not available.');
+ }
+ }
+
+ public function testUsesRequestServerData()
+ {
+ $server = array(
+ 'REQUEST_URI' => 'A',
+ 'REMOTE_ADDR' => 'B',
+ 'REQUEST_METHOD' => 'C',
+ );
+
+ $request = new Request();
+ $request->server->replace($server);
+
+ $processor = new WebProcessor($request);
+ $record = $processor($this->getRecord());
+
+ $this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
+ $this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']);
+ $this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
+ }
+
+ /**
+ * @return array Record
+ */
+ protected function getRecord($level = Logger::WARNING, $message = 'test')
+ {
+ return array(
+ 'message' => $message,
+ 'context' => array(),
+ 'level' => $level,
+ 'level_name' => Logger::getLevelName($level),
+ 'channel' => 'test',
+ 'datetime' => new \DateTime(),
+ 'extra' => array(),
+ );
+ }
+}
View
@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+spl_autoload_register(function ($class) {
+ foreach (array(
+ 'SYMFONY_HTTP_FOUNDATION' => 'HttpFoundation',
+ ) as $env => $name) {
+ if (isset($_SERVER[$env]) && 0 === strpos(ltrim($class, '/'), 'Symfony\Component\\'.$name)) {
+ if (file_exists($file = $_SERVER[$env].'/'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\\'.$name)).'.php')) {
+ require_once $file;
+ }
+ }
+ }
+
+ if (isset($_SERVER['MONOLOG']) && 0 === strpos(ltrim($class, '/'), 'Monolog')) {
+ if (file_exists($file = $_SERVER['MONOLOG'].'/src/'.str_replace('\\', '/', $class).'.php')) {
+ require_once $file;
+ }
+ }
+
+ if (0 === strpos(ltrim($class, '/'), 'Symfony\Bridge\Monolog')) {
+ if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Bridge\Monolog')).'.php')) {
+ require_once $file;
+ }
+ }
+});
View
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="Symfony Monolog Bridge Test Suite">
+ <directory>./Tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./Resources</directory>
+ <directory>./Tests</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>

0 comments on commit 5793297

Please sign in to comment.