[
  {
    "path": ".github/workflows/run-tests.yml",
    "content": "name: run-tests\n\non: ['push']\n\njobs:\n  test:\n    runs-on: ${{ matrix.os }}\n    strategy:\n      fail-fast: true\n      matrix:\n        os: [ubuntu-latest, windows-latest]\n        php: [8.2, 8.3, 8.4, 8.5]\n        laravel: [10.*, 11.*, 12.*, 13.*]\n        stability: [prefer-lowest, prefer-stable]\n        exclude:\n          - php: 8.2\n            laravel: 13.*\n        include:\n          - laravel: 10.*\n            testbench: 8.*\n          - laravel: 11.*\n            testbench: 9.*\n          - laravel: 12.*\n            testbench: 10.*\n          - laravel: 13.*\n            testbench: 11.*\n\n    name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v4\n\n      - name: Setup PHP\n        uses: shivammathur/setup-php@v2\n        with:\n          php-version: ${{ matrix.php }}\n          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo\n          coverage: none\n\n      - name: Install dependencies\n        run: |\n          composer require \"laravel/framework:${{ matrix.laravel }}\" \"orchestra/testbench:${{ matrix.testbench }}\" --no-interaction --no-update\n          composer update --${{ matrix.stability }} --prefer-dist --no-interaction\n\n      - name: Execute tests\n        run: vendor/bin/phpunit\n"
  },
  {
    "path": ".gitignore",
    "content": "/vendor\ncomposer.phar\ncomposer.lock\n.DS_Store\n.idea/"
  },
  {
    "path": "LICENSE.txt",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2014 Dwight Watson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
  },
  {
    "path": "README.md",
    "content": "Active for Laravel\n==================\n\n[![Build Status](https://travis-ci.org/dwightwatson/active.png?branch=master)](https://travis-ci.org/dwightwatson/active)\n[![Total Downloads](https://poser.pugx.org/watson/active/downloads.svg)](https://packagist.org/packages/watson/active)\n[![Latest Stable Version](https://poser.pugx.org/watson/active/v/stable.svg)](https://packagist.org/packages/watson/active)\n[![Latest Unstable Version](https://poser.pugx.org/watson/active/v/unstable.svg)](https://packagist.org/packages/watson/active)\n[![License](https://poser.pugx.org/watson/active/license.svg)](https://packagist.org/packages/watson/active)\n[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/dwightwatson/active)\n\n\nActive is a helper package for Laravel that makes it easy to recognize the current path or route, useful for adding 'active' classes (like those used in the Boostrap framework) and performing other actions only when a certain route is active. It also includes helpers for retrieving the current controller and action names.\n\n## Installation\n\nFirst, simply require the package through Composer.\n\n```sh\ncomposer require watson/active\n```\n\n**Using Laravel 5.1? The latest version of the package that will work for you is 2.0.4.**\n\nNext, add the service provider in your `config/app.php` file.\n\n`Watson\\Active\\ActiveServiceProvider::class`\n\nIf you'd like to use the Facade instead of the helper functions, add it to the `aliases` array.\n\n`'Active' => Watson\\Active\\Facades\\Active::class`\n\n## Using Active\n\n### Helper functions\n\nActive ships with a couple of helper functions which make it easy to use without the facade or creating an instance of your own.\n\n```php\nactive()\nis_active()\n```\n\n### Using `active()`\n\nYou pass an array of routes or paths you want to see are the current page, and if any match this function will return the string `active`, for Bootstrap. Alternatively, you can pass a custom return string as the second argument.\n\n```php\nactive(['login', 'users/*', 'posts.*', 'pages.contact']); // Returns 'active' if the current route matches any path or route name.\n\nactive(['login', 'logout'], 'active-class'); // Returns 'active-class' if the current route is 'login' or 'logout'.\n\nactive(['login', 'logout'], 'active-class', 'fallback-class'); // Returns 'fallback-class' if the current route is not 'login' or 'logout'.\n```\n\nIn the first example, the function will return the string `active` if the current path is `login`, starts with `users/` or if the name of the current route is `posts.create`.\n\nDo note that a number of argument types are provided: you can use a path string, you can use a path string with a wildcard (using the `*`) and you can also use named routes.\n\nYou can use this function with your links to give them an active state.\n\n```php\n<a href=\"{{ route('posts.index') }}\" class=\"{{ active('posts.index') }}\">All posts</a>\n```\n\nYou can also provide certain paths or routes to be exluded when being considered.\n\n```php\nactive(['pages/*', 'not:pages/contact'])\n\nactive(['pages.*', 'not:pages.contact'])\n```\n\n### Using `is_active()`\n\nThis works much the same as `active()`, you can pass the paths and routes to it but instead it will return a boolean if the current page matches.\n\n```php\n@if (is_active('posts/*'))\n    You're looking at a blog post!\n@endif\n```\n\n### Additional helpers\n\nTwo additional functions are provided to get the current controller and action, if your routing is being handled by a controller for a request. These functions will return the lowercase controller/action name, without the method of the request. Here is an example for a request that is routed to `FooController@getBar':\n\n```php\n$controller = controller_name(); // foo\n\n$action = action_name(); // bar\n```\n\n\n## Licence\n\nActive for Laravel is 100% free and open-source, under the [MIT license](LICENSE.txt). Use it however you want.\n\nThis package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/dwightwatson/active) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"watson/active\",\n    \"description\": \"Laravel helper for recognising the current route, controller and action\",\n    \"keywords\": [\n        \"laravel\",\n        \"active\",\n        \"routing\"\n    ],\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Dwight Watson\",\n            \"email\": \"dwight@studiousapp.com\"\n        }\n    ],\n    \"require\": {\n        \"php\": \"^8.2\",\n        \"illuminate/config\": \"^10.0|^11.0||^12.0||^13.0\",\n        \"illuminate/http\": \"^10.0|^11.0||^12.0||^13.0\",\n        \"illuminate/routing\": \"^10.0|^11.0||^12.0||^13.0\",\n        \"illuminate/support\": \"^10.0|^11.0||^12.0||^13.0\"\n    },\n    \"require-dev\": {\n        \"phpunit/phpunit\": \"^9.0|^10.5|^11.0\",\n        \"mockery/mockery\": \"^1.5.1\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Watson\\\\Active\\\\\": \"src/\"\n        },\n        \"files\": [\n            \"src/helpers.php\"\n        ]\n    },\n    \"extra\": {\n        \"laravel\": {\n            \"providers\": [\n                \"Watson\\\\Active\\\\ActiveServiceProvider\"\n            ],\n            \"aliases\": {\n                \"Active\": \"Watson\\\\Watson\\\\Facades\\\\Active\"\n            }\n        }\n    },\n    \"minimum-stability\": \"dev\",\n    \"prefer-stable\": true\n}\n"
  },
  {
    "path": "phpunit.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" backupGlobals=\"false\" backupStaticAttributes=\"false\" bootstrap=\"vendor/autoload.php\" colors=\"true\" convertErrorsToExceptions=\"true\" convertNoticesToExceptions=\"true\" convertWarningsToExceptions=\"true\" processIsolation=\"false\" stopOnFailure=\"false\" xsi:noNamespaceSchemaLocation=\"https://schema.phpunit.de/9.3/phpunit.xsd\">\n  <coverage>\n    <include>\n      <directory suffix=\".php\">src/</directory>\n    </include>\n    <exclude>\n      <directory suffix=\".php\">src/Facades</directory>\n      <file>src/ActiveServiceProvider.php</file>\n    </exclude>\n  </coverage>\n  <testsuites>\n    <testsuite name=\"Package Test Suite\">\n      <directory suffix=\".php\">./tests/</directory>\n    </testsuite>\n  </testsuites>\n</phpunit>\n"
  },
  {
    "path": "src/Active.php",
    "content": "<?php\n\nnamespace Watson\\Active;\n\nuse Illuminate\\Support\\Str;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Routing\\Router;\nuse Illuminate\\Config\\Repository;\n\nclass Active\n{\n    /**\n     * Illuminate Request instance.\n     *\n     * @var \\Illuminate\\Http\\Request\n     */\n    protected $request;\n\n    /**\n     * Illuminate Router instance.\n     *\n     * @var \\Illuminate\\Routing\\Router\n     */\n    protected $router;\n\n    /**\n     * Illuminate Config instance.\n     *\n     * @var \\Illuminate\\Config\\Repository\n     */\n    protected $config;\n\n    /**\n     * Construct the class.\n     *\n     * @param  \\Illuminate\\Http\\Request       $request\n     * @param  \\Illuminate\\Routing\\Router     $router\n     * @param  \\Illuminate\\Config\\Repository  $config\n     * @return void\n     */\n    public function __construct(Request $request, Router $router, Repository $config)\n    {\n        $this->request = $request;\n        $this->router = $router;\n        $this->config = $config;\n    }\n\n    /**\n     * Determine if any of the provided routes are active.\n     *\n     * @param  mixed  $routes\n     * @return bool\n     */\n    public function isActive($routes)\n    {\n        $routes = is_array($routes) ? $routes : func_get_args();\n\n        list($routes, $ignoredRoutes) = $this->parseIgnoredRoutes($routes);\n\n        if ($this->isPath($routes) || $this->isFullPath($routes) || $this->isRoute($routes)) {\n            if (count($ignoredRoutes) && ($this->isPath($ignoredRoutes) || $this->isFullPath($routes) || $this->isRoute($ignoredRoutes))) {\n                return false;\n            }\n\n            return true;\n        }\n\n        return false;\n    }\n\n    /**\n     * Get the active class if the active path is provided.\n     *\n     * @param  mixed $routes\n     * @param  string $class\n     * @param  null  $fallbackClass\n     * @return string|null\n     */\n    public function active($routes, $class = null, $fallbackClass = null)\n    {\n        $routes = (array) $routes;\n\n        if ($this->isActive($routes)) {\n            return $this->getActiveClass($class);\n        }\n\n        if ($fallbackClass) {\n            return $fallbackClass;\n        }\n    }\n\n    /**\n     * Determine if the current path is one of the provided paths.\n     *\n     * @param  mixed   $routes\n     * @return boolean\n     */\n    public function isPath($routes)\n    {\n        $routes = is_array($routes) ? $routes : func_get_args();\n\n        return call_user_func_array([$this->request, 'is'], $routes);\n    }\n\n    /**\n     * Determine if the current full path is one of the provided paths.\n     *\n     * @param  mixed   $routes\n     * @return boolean\n     */\n    public function isFullPath($routes)\n    {\n        $routes = is_array($routes) ? $routes : func_get_args();\n\n        return call_user_func_array([$this->request, 'fullUrlIs'], $routes);\n    }\n\n    /**\n     * Get the active class if the active path is provided.\n     *\n     * @param  mixed   $routes\n     * @param  string  $class\n     * @return string|null\n     */\n    public function path($routes, $class = null)\n    {\n        $routes = (array) $routes;\n\n        if ($this->isPath($routes)) {\n            return $this->getActiveClass($class);\n        }\n    }\n\n    /**\n     * Determin if the current route is one of the provided routes.\n     *\n     * @param  mixed  $routes\n     * @return boolean\n     */\n    public function isRoute($routes)\n    {\n        $routes = is_array($routes) ? $routes : func_get_args();\n\n        return call_user_func_array([$this->router, 'is'], $routes);\n    }\n\n    /**\n     * Get the active class if the active route is provided.\n     *\n     * @param  mixed   $routes\n     * @param  string  $class\n     * @return string|null\n     */\n    public function route($routes, $class = null)\n    {\n        $routes = (array) $routes;\n\n        if ($this->isRoute($routes)) {\n            return $this->getActiveClass($class);\n        }\n    }\n\n    /**\n     * Return the active class if it is provided, otherwise fall back\n     * to the class set in the configuration.\n     *\n     * @param  string  $class\n     * @return string\n     */\n    protected function getActiveClass($class = null)\n    {\n        return $class ?: $this->config->get('active.class');\n    }\n\n    /**\n     * Separate ignored routes from the provided routes.\n     *\n     * @param  mixed  $routes\n     * @return array\n     */\n    private function parseIgnoredRoutes($routes)\n    {\n        $ignoredRoutes = [];\n\n        $routes = is_array($routes) ? $routes : func_get_args();\n\n        foreach ($routes as $index => $route) {\n            if (Str::startsWith($route, 'not:')) {\n                $ignoredRoute = substr($route, 4);\n\n                unset($routes[$index]);\n\n                $ignoredRoutes[] = $ignoredRoute;\n            }\n        }\n\n        return [$routes, $ignoredRoutes];\n    }\n}\n"
  },
  {
    "path": "src/ActiveServiceProvider.php",
    "content": "<?php \n\nnamespace Watson\\Active;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass ActiveServiceProvider extends ServiceProvider\n{\n    /**\n     * Indicates if loading of the provider is deferred.\n     *\n     * @var bool\n     */\n    protected $defer = false;\n\n    /**\n     * Register the service provider.\n     *\n     * @return void\n     */\n    public function register()\n    {\n        $this->app->bind('active', Active::class);\n\n        $this->mergeConfigFrom(\n            __DIR__ . '/config/config.php', 'active'\n        );\n    }\n\n    /**\n     * Bootstrap the application events.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        $this->publishes([\n            __DIR__ . '/config/config.php' => config_path('active.php'),\n        ], 'config');\n    }\n\n    /**\n     * Get the services provided by the provider.\n     *\n     * @return array\n     */\n    public function provides()\n    {\n        return ['active'];\n    }\n}\n"
  },
  {
    "path": "src/Facades/Active.php",
    "content": "<?php \n\nnamespace Watson\\Active\\Facades;\n\nuse Illuminate\\Support\\Facades\\Facade;\n\nclass Active extends Facade\n{\n    /**\n     * Get the registered name of the component.\n     *\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    protected static function getFacadeAccessor()\n    {\n        return 'active';\n    }\n}\n"
  },
  {
    "path": "src/Route.php",
    "content": "<?php\n\nnamespace Watson\\Active;\n\nuse Illuminate\\Routing\\Router;\nuse Illuminate\\Support\\Str;\n\nclass Route\n{    \n    /**\n     * Illuminate Router instance.\n     *\n     * @var \\Illuminate\\Routing\\Router\n     */\n    protected $router;\n\n    /** \n     * Construct the class.\n     *\n     * @param  \\Illuminate\\Routing\\Router  $router\n     * @return void\n     */\n    public function __construct(Router $router)\n    {\n        $this->router = $router;\n    }\n\n    /**\n     * Get the controller name, separated as necessary and with or without namespaces.\n     *\n     * @param  string  $separator\n     * @param  bool    $includeNamespace\n     * @param  string  $trimNamespace\n     * @return string|null\n     */\n    public function controller($separator = null, $includeNamespace = true, $trimNamespace = 'App\\Http\\Controllers\\\\')\n    {\n        if ($action = $this->router->currentRouteAction()) {\n            $separator = is_null($separator) ? ' ' : $separator;\n\n            $controller = head(Str::parseCallback($action, null));\n\n            // If the controller contains the given namespace, remove it.\n            if (substr($controller, 0, strlen($trimNamespace)) === $trimNamespace) {\n                $controller = substr($controller, strlen($trimNamespace));\n            }\n\n            // If the controller contains 'Controller' at the end, remove it.\n            if (substr($controller, - strlen('Controller')) === 'Controller') {\n                $controller = substr($controller, 0, - strlen('Controller'));\n            }\n\n            // Separate out nested controller resources.\n            $controller = str_replace('_', $separator, Str::snake($controller));\n\n            // Either separate out the namespaces or remove them.\n            $controller = $includeNamespace ? str_replace('\\\\', '', $controller) : substr(strrchr($controller, '\\\\'), 1);\n\n            return trim($controller);\n        }\n\n        return null;\n    }\n\n    /**\n     * Get the current controller action name.\n     *\n     * @param  bool  $removeHttpMethod\n     * @return string|null\n     */\n    public function action($removeHttpMethod = true)\n    {\n        if ($action = $this->router->currentRouteAction()) {\n            $action = last(Str::parseCallback($action, null));\n\n            if ($removeHttpMethod) {\n                $action = str_replace(['get', 'post', 'patch', 'put', 'delete'], '', $action);\n            }\n\n            return Str::snake($action, '-');\n        }\n\n        return null;\n    }\n}\n"
  },
  {
    "path": "src/config/config.php",
    "content": "<?php\n\nreturn [\n\n    /*\n    |--------------------------------------------------------------------------\n    | Active class\n    |--------------------------------------------------------------------------\n    |\n    | Here you may set the class string to be returned when the provided routes\n    | or paths were identified as applicable for the current route.\n    |\n    */\n\n    'class' => 'active',\n\n];\n"
  },
  {
    "path": "src/helpers.php",
    "content": "<?php\n\nuse Watson\\Active\\Route;\nuse Illuminate\\Support\\Facades\\App;\n\nif ( ! function_exists('controller_name')) {\n    /**\n     * Get the controller name, separated as necessary and with or without namespaces.\n     *\n     * @param  string  $separator\n     * @param  bool    $includeNamespace\n     * @param  string  $trimNamespace\n     * @return string|null\n     */\n    function controller_name($separator = null, $includeNamespace = true, $trimNamespace = 'App\\Http\\Controllers\\\\')\n    {\n        return App::make(Route::class)->controller($separator, $includeNamespace, $trimNamespace);\n    }\n}\n\nif ( ! function_exists('action_name')) {\n    /**\n     * Get the current controller action name.\n     *\n     * @param  bool  $removeHttpMethod\n     * @return string|null\n     */\n    function action_name($removeHttpMethod = true)\n    {\n        return App::make(Route::class)->action($removeHttpMethod);\n    }\n}\n\nif ( ! function_exists('active')) {\n    /**\n     * Get the active class if an active path is provided.\n     *\n     * @param  mixed $routes\n     * @param  string $class\n     * @param  null  $fallbackClass\n     * @return string|null\n     */\n    function active($routes = null, $class = null, $fallbackClass = null)\n    {\n        if (is_null($routes)) {\n            return App::make('active');\n        }\n\n        $routes = is_array($routes) ? $routes : [$routes];\n\n        return active()->active($routes, $class, $fallbackClass);\n    }\n}\n\nif ( ! function_exists('is_active')) {\n    /**\n     * Determine if any of the provided routes are active.\n     *\n     * @param  mixed  $routes\n     * @return bool\n     */\n    function is_active($routes)\n    {\n        $routes = is_array($routes) ? $routes : func_get_args();\n\n        return active()->isActive($routes);\n    }\n}\n"
  },
  {
    "path": "tests/.gitkeep",
    "content": ""
  },
  {
    "path": "tests/ActiveTest.php",
    "content": "<?php\n\nuse Watson\\Active\\Active;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Routing\\Router;\nuse PHPUnit\\Framework\\TestCase;\nuse Illuminate\\Config\\Repository;\n\nclass ActiveTest extends TestCase\n{\n    protected $active;\n\n    protected $request;\n\n    protected $router;\n\n    protected $config;\n\n    protected function setUp(): void\n    {\n        parent::setUp();\n\n        $this->request = Mockery::mock(Request::class);\n        $this->router = Mockery::mock(Router::class);\n        $this->config = Mockery::mock(Repository::class);\n\n        $this->active = new Active($this->request, $this->router, $this->config);\n    }\n\n    protected function tearDown(): void\n    {\n        parent::tearDown();\n\n        Mockery::close();\n    }\n\n    /** @test */\n    public function is_active_returns_true_when_on_path()\n    {\n        $this->request->shouldReceive('is')->with('foo')->andReturn(true);\n\n        $result = $this->active->isActive('foo');\n\n        $this->assertTrue($result, \"False returned when current path provided.\");\n    }\n\n    /** @test */\n    public function is_active_returns_true_when_on_full_path()\n    {\n        $this->request->shouldReceive('is')->with('/foo')->andReturn(true);\n        $this->request->shouldReceive('fullUrlIs')->with('/foo')->andReturn(true);\n\n        $result = $this->active->isActive('/foo');\n\n        $this->assertTrue($result, \"False returned when current path provided.\");\n    }\n\n    /** @test */\n    public function is_active_returns_true_when_on_route()\n    {\n        $this->request->shouldReceive('is')->with('home')->andReturn(false);\n        $this->request->shouldReceive('fullUrlIs')->with('home')->andReturn(false);\n        $this->router->shouldReceive('is')->with('home')->andReturn(true);\n\n        $result = $this->active->isActive('home');\n\n        $this->assertTrue($result, \"False returned when current route provided.\");\n    }\n\n    /** @test */\n    public function is_active_returns_false_when_on_ignored_path()\n    {\n        $this->request->shouldReceive('is')->with('foo/*')->andReturn(true);\n        $this->request->shouldReceive('is')->with('foo/bar')->andReturn(true);\n\n        $result = $this->active->isActive('foo/*', 'not:foo/bar');\n\n        $this->assertFalse($result, \"Returned true when on an ignored path.\");\n    }\n\n    /** @test */\n    public function is_active_returns_false_when_on_ignored_route()\n    {\n        $this->request->shouldReceive('is')->with('pages.*')->andReturn(false);\n        $this->request->shouldReceive('is')->with('pages.show')->andReturn(false);\n        $this->request->shouldReceive('fullUrlIs')->with('pages.*')->andReturn(false);\n        $this->request->shouldReceive('fullUrlIs')->with('pages.show')->andReturn(false);\n\n        $this->router->shouldReceive('is')->with('pages.*')->andReturn(true);\n        $this->router->shouldReceive('is')->with('pages.show')->andReturn(true);\n\n        $result = $this->active->isActive('pages.*', 'not:pages.show');\n\n        $this->assertFalse($result, \"Returned true when on an ignored route.\");\n    }\n\n    /** @test */\n    public function is_active_returns_false_when_not_on_path_or_route()\n    {\n        $this->request->shouldReceive('is')->with('foo')->andReturn(false);\n        $this->request->shouldReceive('fullUrlIs')->with('foo')->andReturn(false);\n        $this->router->shouldReceive('is')->with('foo')->andReturn(false);\n\n        $result = $this->active->isActive('foo');\n\n        $this->assertFalse($result, \"Returned true when the current route or path is not provided.\");\n    }\n\n\n    /** @test */\n    public function active_returns_active_when_on_path()\n    {\n        $this->request->shouldReceive('is')->with('foo')->andReturn(true);\n        $this->request->shouldReceive('is')->with()->andReturn(false);\n\n        $this->config->shouldReceive('get')->with('active.class')->once()->andReturn('active');\n\n        $result = $this->active->active('foo');\n\n        $this->assertEquals('active', $result, \"Wrong string returned when current path provided.\");\n    }\n\n    /** @test */\n    public function active_returns_provided_class_when_on_path()\n    {\n        $this->request->shouldReceive('is')->with('foo')->andReturn(true);\n        $this->request->shouldReceive('is')->with()->andReturn(false);\n\n        $result = $this->active->active('foo', 'active');\n\n        $this->assertEquals('active', $result, \"Wrong string returned when current path provided.\");\n    }\n\n    /** @test */\n    public function active_returns_provided_string_when_on_path()\n    {\n        $this->request->shouldReceive('is')->with('foo')->andReturn(true);\n        $this->request->shouldReceive('is')->with()->andReturn(false);\n\n        $result = $this->active->active('foo', 'bar');\n\n        $this->assertEquals('bar', $result, \"Wrong string returned when current path provided.\");\n    }\n\n    /** @test */\n    public function active_returns_null_when_not_on_path()\n    {\n        $this->request->shouldReceive('is')->with('foo')->andReturn(false);\n        $this->request->shouldReceive('fullUrlIs')->with('foo')->andReturn(false);\n        $this->router->shouldReceive('is')->with('foo')->andReturn(false);\n\n        $result = $this->active->active('foo');\n\n        $this->assertNull($result, \"Returned string when the current route or path is not provided.\");\n    }\n\n    /** @test */\n    public function active_returns_fallback_when_not_on_path()\n    {\n        $this->request->shouldReceive('is')->with('foo')->andReturn(false);\n        $this->request->shouldReceive('fullUrlIs')->with('foo')->andReturn(false);\n        $this->router->shouldReceive('is')->with('foo')->andReturn(false);\n\n        $result = $this->active->active('foo', 'active', 'inactive');\n\n        $this->assertEquals('inactive', $result);\n    }\n\n\n    /** @test */\n    public function path_returns_active_when_on_path()\n    {\n        $this->request->shouldReceive('is')->andReturn(true);\n\n        $this->config->shouldReceive('get')->with('active.class')->once()->andReturn('active');\n\n        $result = $this->active->path('foo');\n\n        $this->assertEquals('active', $result, \"Class is not returned when path is matched.\");\n    }\n\n    /** @test */\n    public function path_returns_provided_string_when_on_path()\n    {\n        $this->request->shouldReceive('is')->andReturn(true);\n\n        $result = $this->active->path('foo', 'bar');\n\n        $this->assertEquals('bar', $result, \"Incorrect class is returned when path is matched.\");\n    }\n\n    /** @test */\n    public function path_returns_null_when_not_current_path()\n    {\n        $this->request->shouldReceive('is')->andReturn(false);\n\n        $result = $this->active->path('foo');\n\n        $this->assertNull($result, \"Null is not returend when path is not matched.\");\n    }\n\n    /** @test */\n    public function route_returns_active_when_on_route()\n    {\n        $this->router->shouldReceive('is')->andReturn(true);\n\n        $this->config->shouldReceive('get')->with('active.class')->once()->andReturn('active');\n\n        $result = $this->active->route('foo');\n\n        $this->assertEquals('active', $result, \"Class is not returned when route is matched.\");\n    }\n\n    /** @test */\n    public function route_returns_provided_string_when_on_route()\n    {\n        $this->router->shouldReceive('is')->andReturn(true);\n\n        $result = $this->active->route('foo', 'bar');\n\n        $this->assertEquals('bar', $result, \"Class is not returned when route is matched.\");\n    }\n\n    /** @test */\n    public function route_returns_null_when_not_current_route()\n    {\n        $this->router->shouldReceive('is')->andReturn(false);\n\n        $result = $this->active->route('foo');\n\n        $this->assertNull($result, \"Null is not returned when route is not matched.\");\n    }\n}\n"
  },
  {
    "path": "tests/RouteTest.php",
    "content": "<?php\n\nuse Watson\\Active\\Route;\nuse Illuminate\\Routing\\Router;\nuse PHPUnit\\Framework\\TestCase;\n\nclass RouteTest extends TestCase\n{\n    protected $route;\n\n    protected $router;\n\n    protected function setUp(): void\n    {\n        parent::setUp();\n\n        $this->router = Mockery::mock(Router::class);\n\n        $this->route = new Route($this->router);\n    }\n\n    protected function tearDown(): void\n    {\n        parent::tearDown();\n\n        Mockery::close();\n    }\n\n    /** @test */\n    public function controller_gets_controller_name()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('App\\Http\\Controllers\\FooController@bar');\n\n        $result = $this->route->controller();\n\n        $this->assertEquals('foo', $result, \"Does not get correct controller name.\");\n    }\n\n    /** @test */\n    public function controller_gets_namespaced_controller_name()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('App\\Http\\Controllers\\Baz\\FooController@bar');\n\n        $result = $this->route->controller();\n\n        $this->assertEquals('baz foo', $result, \"Does not get the correct namespaced controller name.\");\n    }\n\n    /** @test */\n    public function controller_gets_namespaced_controller_with_separator()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('App\\Http\\Controllers\\Baz\\FooController@bar');\n\n        $result = $this->route->controller('-');\n\n        $this->assertEquals('baz-foo', $result, \"Does not get the correct separated namespaced controller name.\");\n    }\n\n    /** @test */\n    public function controller_gets_controller_without_namespace()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('App\\Http\\Controllers\\Baz\\FooController@bar');\n\n        $result = $this->route->controller(null, false);\n\n        $this->assertEquals('foo', $result, \"Does not get controller name without namespace.\");\n    }\n\n    /** @test */\n    public function controller_gets_controller_with_alternate_namespace()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('Platform\\Controllers\\Baz\\FooController@bar');\n\n        $result = $this->route->controller(null, true, 'Platform\\Controllers');\n\n        $this->assertEquals('baz foo', $result, \"Does not trim alternate namespace from controller.\");\n    }\n\n    /** @test */\n    public function controller_returns_null_when_not_on_controller()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn(null);\n\n        $result = $this->route->controller();\n\n        $this->assertNull($result, \"Does not return null when not on controller route.\");\n    }\n\n\n    /** @test */\n    public function action_gets_action_name()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('FooController@bar');\n\n        $result = $this->route->action();\n\n        $this->assertEquals('bar', $result, \"Does not get correct action name.\");\n    }\n\n    /** @test */\n    public function action_gets_kebab_case()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('FooController@barBaz');\n\n        $result = $this->route->action();\n\n        $this->assertEquals('bar-baz', $result, \"Does not get correct action name.\");\n    }\n\n    /** @test */\n    public function action_removes_http_method()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('FooController@getBar');\n\n        $result = $this->route->action(true);\n\n        $this->assertEquals('bar', $result, \"Does not remove the method from the action.\");\n    }\n\n    /** @test */\n    public function action_does_not_remove_http_method()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn('FooController@getBar');\n\n        $result = $this->route->action(false);\n\n        $this->assertEquals('get-bar', $result, \"Removes the method from the action.\");\n    }\n\n    /** @test */\n    public function action_returns_null_when_not_on_controller()\n    {\n        $this->router->shouldReceive('currentRouteAction')->once()->andReturn(null);\n\n        $result = $this->route->action();\n\n        $this->assertNull($result, \"Does not return null when not on controller route.\");\n    }\n}\n"
  },
  {
    "path": "tests/helpersTest.php",
    "content": "<?php\n\nuse Watson\\Active\\Route;\nuse Watson\\Active\\Active;\nuse PHPUnit\\Framework\\TestCase;\nuse Illuminate\\Support\\Facades\\App;\n\nclass HelpersTest extends TestCase\n{\n    protected function tearDown(): void\n    {\n        parent::tearDown();\n\n        Mockery::close();\n    }\n\n    /** @test */\n    public function controller_name_calls_controller_method()\n    {\n        $routeMock = Mockery::mock(Route::class);\n\n        $routeMock->shouldReceive('controller')->once()->with('foo', 'bar', 'baz')->andReturn('bat');\n\n        App::shouldReceive('make')->once()->with(Route::class)->andReturn($routeMock);\n\n        $result = controller_name('foo', 'bar', 'baz');\n\n        $this->assertEquals('bat', $result);\n    }\n\n    /** @test */\n    public function action_name_calls_action_method()\n    {\n        $routeMock = Mockery::mock(Route::class);\n\n        $routeMock->shouldReceive('action')->once()->with('foo')->andReturn('bar');\n\n        App::shouldReceive('make')->once()->with(Route::class)->andReturn($routeMock);\n\n        $result = action_name('foo');\n\n        $this->assertEquals('bar', $result);\n    }\n\n    /** @test */\n    public function action_without_parameters_returns_instance()\n    {\n        $activeMock = Mockery::mock(Active::class);\n\n        App::shouldReceive('make')->once()->with('active')->andReturn($activeMock);\n\n        $result = active();\n\n        $this->assertEquals($activeMock, $result);\n    }\n\n    /** @test */\n    public function active_calls_active_method()\n    {\n        $activeMock = Mockery::mock(Active::class);\n\n        $activeMock->shouldReceive('active')->once()->with(['foo'], 'bar', null)->andReturn('baz');\n\n        App::shouldReceive('make')->once()->with('active')->andReturn($activeMock);\n\n        $result = active('foo', 'bar');\n\n        $this->assertEquals('baz', $result);\n    }\n\n    /** @test */\n    public function is_active_calls_is_active_method()\n    {\n        $activeMock = Mockery::mock(Active::class);\n\n        $activeMock->shouldReceive('isActive')->once()->with(['foo'])->andReturn('bar');\n\n        App::shouldReceive('make')->once()->with('active')->andReturn($activeMock);\n\n        $result = is_active('foo');\n\n        $this->assertEquals('bar', $result);\n    }\n}\n"
  }
]