Explorar o código

Fixed some CS and Unique-generation-value name

* Fixed config name, and updated code and documentation. Fixes #58.
* GearmanClientCallbackExceptionEvent now extends Event. Fixes #59.
* Also tested instanceOf in Events.
Marc %!s(int64=11) %!d(string=hai) anos
pai
achega
ec55d9cbdf

+ 4 - 4
DependencyInjection/Configuration.php

@@ -78,13 +78,13 @@ class Configuration implements ConfigurationInterface
                             ->defaultValue('doNormal')
                         ->end()
                         ->scalarNode('callbacks')
-                            ->defaultValue(true)
+                            ->defaultTrue()
                         ->end()
                         ->scalarNode('job_prefix')
-                            ->defaultValue(null)
+                            ->defaultNull()
                         ->end()
-                        ->scalarNode('generate-unique-key')
-                            ->defaultValue(true)
+                        ->scalarNode('generate_unique_key')
+                            ->defaultTrue()
                         ->end()
                     ->end()
                 ->end()

+ 1 - 1
README.md

@@ -155,7 +155,7 @@ Also we must config gearman cache, using doctrine cache.
             
             # Autogenerate unique key in jobs/tasks if not set
             # This key is unique given a Job name and a payload serialized
-            generate-unique-key: true
+            generate_unique_key: true
 
         # Server list where workers and clients will connect to
         # Each server must contain host and port

+ 9 - 5
Service/GearmanClient.php

@@ -167,7 +167,8 @@ class GearmanClient extends AbstractGearmanService
     {
         $worker = $this->getJob($jobName);
 
-        if ($this->settings['generate-unique-key']) {
+        if ($this->settings['generate_unique_key']) {
+
             $unique = $this->generateUniqueKey($jobName, $params);
         }
 
@@ -533,7 +534,8 @@ class GearmanClient extends AbstractGearmanService
      */
     private function enqueueTask($name, $params, $context, $unique, $method)
     {
-        if ($this->settings['generate-unique-key']) {
+        if ($this->settings['generate_unique_key']) {
+
             $unique = $this->generateUniqueKey($name, $params);
         }
 
@@ -599,12 +601,14 @@ class GearmanClient extends AbstractGearmanService
         return $gearmanClient->runTasks();
     }
 
+
     /**
      * Generates a unique string if null
      *
-     * @param string $name
-     * @param string $params
-     * @return string
+     * @param string $name   Name of the Worker/Job 
+     * @param string $params Params
+     *
+     * @return string Unique string generated for given object and params
      */
     private function generateUniqueKey($name, $params = '')
     {

+ 10 - 0
Tests/Event/GearmanClientCallbackCompleteEventTest.php

@@ -50,4 +50,14 @@ class GearmanClientCallbackCompleteEventTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->gearmanClientCallbackCompleteEvent->getGearmanTask(), $this->gearmanTask);
     }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackCompleteEvent);
+        $this->assertInstanceOf('Mmoreram\GearmanBundle\Event\Abstracts\AbstractGearmanClientTaskEvent', $this->gearmanClientCallbackCompleteEvent);
+    }
 }

+ 10 - 0
Tests/Event/GearmanClientCallbackCreatedEventTest.php

@@ -50,4 +50,14 @@ class GearmanClientCallbackCreatedEventTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->gearmanClientCallbackCreatedEvent->getGearmanTask(), $this->gearmanTask);
     }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackCreatedEvent);
+        $this->assertInstanceOf('Mmoreram\GearmanBundle\Event\Abstracts\AbstractGearmanClientTaskEvent', $this->gearmanClientCallbackCreatedEvent);
+    }
 }

+ 10 - 0
Tests/Event/GearmanClientCallbackDataEventTest.php

@@ -50,4 +50,14 @@ class GearmanClientCallbackDataEventTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->gearmanClientCallbackDataEvent->getGearmanTask(), $this->gearmanTask);
     }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackDataEvent);
+        $this->assertInstanceOf('Mmoreram\GearmanBundle\Event\Abstracts\AbstractGearmanClientTaskEvent', $this->gearmanClientCallbackDataEvent);
+    }
 }

+ 43 - 0
Tests/Event/GearmanClientCallbackExceptionEventTest.php

@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * RSQueueBundle for Symfony2
+ *
+ * Marc Morera 2013
+ */
+
+namespace Mmoreram\GearmanBundle\Tests\Event;
+
+use Mmoreram\GearmanBundle\Event\GearmanClientCallbackExceptionEvent;
+
+/**
+ * Tests GearmanClientCallbackExceptionEventTest class
+ */
+class GearmanClientCallbackExceptionEventTest extends \PHPUnit_Framework_TestCase
+{
+
+    /**
+     * @var GearmanClientCallbackExceptionEvent
+     *
+     * Object to test
+     */
+    private $gearmanClientCallbackExceptionEvent;
+
+
+    /**
+     * Setup
+     */
+    public function setUp()
+    {
+        $this->gearmanClientCallbackExceptionEvent = new GearmanClientCallbackExceptionEvent($this->gearmanTask);
+    }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackExceptionEvent);
+    }
+}

+ 10 - 0
Tests/Event/GearmanClientCallbackFailEventTest.php

@@ -50,4 +50,14 @@ class GearmanClientCallbackFailEventTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->gearmanClientCallbackFailEvent->getGearmanTask(), $this->gearmanTask);
     }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackFailEvent);
+        $this->assertInstanceOf('Mmoreram\GearmanBundle\Event\Abstracts\AbstractGearmanClientTaskEvent', $this->gearmanClientCallbackFailEvent);
+    }
 }

+ 10 - 0
Tests/Event/GearmanClientCallbackStatusEventTest.php

@@ -50,4 +50,14 @@ class GearmanClientCallbackStatusEventTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->gearmanClientCallbackStatusEvent->getGearmanTask(), $this->gearmanTask);
     }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackStatusEvent);
+        $this->assertInstanceOf('Mmoreram\GearmanBundle\Event\Abstracts\AbstractGearmanClientTaskEvent', $this->gearmanClientCallbackStatusEvent);
+    }
 }

+ 10 - 0
Tests/Event/GearmanClientCallbackWarningEventTest.php

@@ -50,4 +50,14 @@ class GearmanClientCallbackWarningEventTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->gearmanClientCallbackWarningEvent->getGearmanTask(), $this->gearmanTask);
     }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackWarningEvent);
+        $this->assertInstanceOf('Mmoreram\GearmanBundle\Event\Abstracts\AbstractGearmanClientTaskEvent', $this->gearmanClientCallbackWarningEvent);
+    }
 }

+ 10 - 0
Tests/Event/GearmanClientCallbackWorkloadEventTest.php

@@ -50,4 +50,14 @@ class GearmanClientCallbackWorkloadEventTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals($this->gearmanClientCallbackWorkloadEvent->getGearmanTask(), $this->gearmanTask);
     }
+
+
+    /**
+     * Tests if Event extends needed classes
+    */
+    public function testInstancesOf()
+    {
+        $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->gearmanClientCallbackWorkloadEvent);
+        $this->assertInstanceOf('Mmoreram\GearmanBundle\Event\Abstracts\AbstractGearmanClientTaskEvent', $this->gearmanClientCallbackWorkloadEvent);
+    }
 }