Skip to content

Commit

Permalink
Merge pull request #28 from richardbishopme/master
Browse files Browse the repository at this point in the history
ClassFinder: Fix issue with old string helper methods
  • Loading branch information
Christoph Rumpel authored Oct 28, 2019
2 parents 07c2a30 + a95cc66 commit cdf56cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ClassFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Christophrumpel\NovaNotifications;

use ReflectionClass;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;

class ClassFinder
Expand All @@ -24,7 +25,7 @@ public function find(string $nameSpace): Collection
$composer = require base_path('vendor/autoload.php');

return collect($composer->getClassMap())->filter(function ($value, $key) use ($nameSpace) {
return starts_with($key, $nameSpace);
return Str::startsWith($key, $nameSpace);
});
}

Expand All @@ -47,7 +48,7 @@ public function findByExtending(string $classNameToFind, array $namespacesToSear
->filter(function ($className) use ($namespacesToSearch) {
return collect($namespacesToSearch)
->filter(function ($namespace) use ($className) {
return starts_with($className, $namespace);
return Str::startsWith($className, $namespace);
})
->count();
})
Expand Down
36 changes: 36 additions & 0 deletions tests/ClassFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Christophrumpel\NovaNotifications\tests;

use Christophrumpel\NovaNotifications\ClassFinder;

class ClassFinderTest extends TestCase
{
/**
* @test
**/
public function it_find_classes()
{
$this->app->setBasePath(__DIR__.'/..');

$classFinder = app(ClassFinder::class);

$response = $classFinder->find('Illuminate\Database\Eloquent\Model', ['App']);

$this->assertInstanceOf('Illuminate\Support\Collection', $response);
}

/**
* @test
**/
public function it_find_classes_which_are_extending_a_specific_class()
{
$this->app->setBasePath(__DIR__.'/..');

$classFinder = app(ClassFinder::class);

$response = $classFinder->findByExtending('Illuminate\Database\Eloquent\Model', ['App']);

$this->assertInstanceOf('Illuminate\Support\Collection', $response);
}
}

0 comments on commit cdf56cc

Please sign in to comment.