Browse Source

Fixed code style and improved tests for Laraval provider

Florian Eckerstorfer 10 years ago
parent
commit
7412804ad1

+ 25 - 4
src/Bridge/Laravel/SlugifyFacade.php

@@ -1,18 +1,39 @@
-<?php namespace Cocur\Slugify\Bridge\Laravel;
+<?php
 
-use Illuminate\Support\Facades\Facade;
+/**
+ * This file is part of cocur/slugify.
+ *
+ * (c) Florian Eckerstorfer <florian@eckerstorfer.co>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
 
+namespace Cocur\Slugify\Bridge\Laravel;
 
-class SlugifyFacade extends Facade {
+use Illuminate\Support\Facades\Facade;
 
+/**
+ * SlugifyServiceProvider
+ *
+ * @package    cocur/slugify
+ * @subpackage bridge
+ * @author     Florian Eckerstorfer <florian@eckerstorfer.co>
+ * @author     Colin Viebrock
+ * @copyright  2012-2014 Florian Eckerstorfer
+ * @license    http://www.opensource.org/licenses/MIT The MIT License
+ */
+class SlugifyFacade extends Facade
+{
     /**
      * Get the registered name of the component.
      *
      * @return string
+     *
+     * @codeCoverageIgnore
      */
     protected static function getFacadeAccessor()
     {
         return 'slugify';
     }
-
 }

+ 17 - 6
src/Bridge/Laravel/SlugifyServiceProvider.php

@@ -1,22 +1,32 @@
-<?php namespace Cocur\Slugify\Bridge\Laravel;
+<?php
+
+/**
+ * This file is part of cocur/slugify.
+ *
+ * (c) Florian Eckerstorfer <florian@eckerstorfer.co>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Cocur\Slugify\Bridge\Laravel;
 
 use Cocur\Slugify\Slugify;
 use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
 use Illuminate\Foundation\Application;
 
-
 /**
  * SlugifyServiceProvider
  *
  * @package    cocur/slugify
  * @subpackage bridge
  * @author     Florian Eckerstorfer <florian@eckerstorfer.co>
+ * @author     Colin Viebrock
  * @copyright  2012-2014 Florian Eckerstorfer
  * @license    http://www.opensource.org/licenses/MIT The MIT License
  */
 class SlugifyServiceProvider extends LaravelServiceProvider
 {
-
     /**
      * Indicates if loading of the provider is deferred.
      *
@@ -29,7 +39,8 @@ class SlugifyServiceProvider extends LaravelServiceProvider
      *
      * @return void
      */
-    public function register() {
+    public function register()
+    {
         $this->app->bindShared('slugify', function (Application $app) {
             return new Slugify();
         });
@@ -40,8 +51,8 @@ class SlugifyServiceProvider extends LaravelServiceProvider
      *
      * @return array
      */
-    public function provides() {
+    public function provides()
+    {
         return array('slugify');
     }
-
 }

+ 3 - 3
src/Slugify.php

@@ -456,12 +456,12 @@ class Slugify implements SlugifyInterface
     );
 
     /**
-     * Returns the slugified string.
+     * Returns the slug-version of the string.
      *
      * @param string $string    String to slugify
      * @param string $separator Separator
      *
-     * @return string Slugified string
+     * @return string Slug-verison of the string
      */
     public function slugify($string, $separator = '-')
     {
@@ -473,7 +473,7 @@ class Slugify implements SlugifyInterface
     }
 
     /**
-     * Adds a custom rule to the slugifier.
+     * Adds a custom rule to the Slugify.
      *
      * @param string $character   Character
      * @param string $replacement Replacement character

+ 28 - 8
tests/Bridge/Laravel/SlugifyLaravelProviderTest.php → tests/Bridge/Laravel/SlugifyProviderTest.php

@@ -12,6 +12,7 @@
 namespace Cocur\Slugify\Bridge\Laravel;
 
 use Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider;
+use Illuminate\Foundation\Application;
 
 /**
  * SlugifyServiceProviderTest
@@ -20,27 +21,46 @@ use Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider;
  * @package    cocur/slugify
  * @subpackage bridge
  * @author     Florian Eckerstorfer <florian@eckerstorfer.co>
+ * @author     Colin Viebrock
  * @copyright  2012-2014 Florian Eckerstorfer
  * @license    http://www.opensource.org/licenses/MIT The MIT License
  * @group      unit
  */
 class SlugifyServiceProviderTest extends \PHPUnit_Framework_TestCase
 {
+    /** @var Application */
+    private $app;
+
+    /** @var SlugifyServiceProvider */
+    private $provider;
+
+    public function setUp()
+    {
+        $this->app = new Application();
+        $this->provider = new SlugifyServiceProvider($this->app);
+    }
 
     /**
      * @test
      * @covers Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider::register()
      */
-    public function register()
+    public function registerRegistersTheServiceProvider()
     {
-        // it seems like Application is not mockable.
-        $app = new \Illuminate\Foundation\Application();
-        $provider = new SlugifyServiceProvider($app);
-        $provider->register();
+        $this->provider->register();
+
         // the service provider is deferred, so this forces it to load
-        $slugify = $app->make('slugify');
+        $this->app->make('slugify');
 
-        $this->assertArrayHasKey('slugify', $app);
-        $this->assertInstanceOf('Cocur\Slugify\Slugify', $app['slugify']);
+        $this->assertArrayHasKey('slugify', $this->app);
+        $this->assertInstanceOf('Cocur\Slugify\Slugify', $this->app['slugify']);
+    }
+
+    /**
+     * @test
+     * @covers Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider::provides()
+     */
+    public function containsReturnsTheNameOfThProvider()
+    {
+        $this->assertContains('slugify', $this->provider->provides());
     }
 }