Skip to content

Commit

Permalink
Adding helpers file. Adding a module_name helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
nWidart committed Jun 9, 2017
1 parent b081d58 commit 114b334
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All Notable changes to `laravel-modules` will be documented in this file.

- A `--migration` flag to the `module:make-model` command to generate the migration file with a model
- Factories are now also defined in the master service providers. This is used in the `module:make` command without the `--plain` flag, or using `module:make-provider` with the `--master` flag.
- `module_path()` helper function.

## Changed

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"autoload": {
"psr-4": {
"Nwidart\\Modules\\": "src"
}
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

if (! function_exists('module_path')) {
function module_path($name)
{
$module = app('modules')->find($name);

return $module->getPath();
}
}
35 changes: 35 additions & 0 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Nwidart\Modules\tests;

class HelpersTest extends BaseTestCase
{
/**
* @var \Illuminate\Filesystem\Filesystem
*/
private $finder;
/**
* @var string
*/
private $modulePath;

public function setUp()
{
parent::setUp();
$this->modulePath = base_path('modules/Blog');
$this->finder = $this->app['files'];
$this->artisan('module:make', ['name' => ['Blog']]);
}

public function tearDown()
{
$this->finder->deleteDirectory($this->modulePath);
parent::tearDown();
}

/** @test */
public function it_finds_the_module_path()
{
$this->assertTrue(str_contains(module_path('Blog'), 'modules/Blog'));
}
}

0 comments on commit 114b334

Please sign in to comment.