Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Configure application namespace while discovering events #28145

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Illuminate/Foundation/Events/DiscoverEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ protected static function classFromFile(SplFileInfo $file, $basePath)
{
$class = trim(str_replace($basePath, '', $file->getRealPath()), DIRECTORY_SEPARATOR);

return str_replace(DIRECTORY_SEPARATOR, '\\', ucfirst(Str::replaceLast('.php', '', $class)));
return str_replace(
[DIRECTORY_SEPARATOR, 'App\\'],
['\\', app()->getNamespace()],
ucfirst(Str::replaceLast('.php', '', $class))
);
}
}
7 changes: 0 additions & 7 deletions tests/Foundation/Fixtures/EventDiscovery/Events/EventOne.php

This file was deleted.

7 changes: 0 additions & 7 deletions tests/Foundation/Fixtures/EventDiscovery/Events/EventTwo.php

This file was deleted.

24 changes: 0 additions & 24 deletions tests/Foundation/Fixtures/EventDiscovery/Listeners/Listener.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

namespace Illuminate\Tests\Foundation;
namespace Illuminate\Tests\Integration\Foundation;

use PHPUnit\Framework\TestCase;
use Orchestra\Testbench\TestCase;
use Illuminate\Foundation\Events\DiscoverEvents;
use Illuminate\Tests\Foundation\Fixtures\EventDiscovery\Events\EventOne;
use Illuminate\Tests\Foundation\Fixtures\EventDiscovery\Events\EventTwo;
use Illuminate\Tests\Foundation\Fixtures\EventDiscovery\Listeners\Listener;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventOne;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventTwo;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener;

class DiscoverEventsTest extends TestCase
{
public function test_events_can_be_discovered()
{
class_alias(Listener::class, 'Tests\Foundation\Fixtures\EventDiscovery\Listeners\Listener');
class_alias(Listener::class, 'Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener');

$events = DiscoverEvents::within(__DIR__.'/Fixtures/EventDiscovery/Listeners', getcwd());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events;

class EventOne
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events;

class EventTwo
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners;

use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventOne;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventTwo;

class Listener
{
public function handle(EventOne $event)
{
//
}

public function handleEventOne(EventOne $event)
{
//
}

public function handleEventTwo(EventTwo $event)
{
//
}
}