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

[9.x] Enforce Mockery m aliasing consistency #41173

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Enforce Mockery m aliasing
  • Loading branch information
lucasmichot committed Feb 22, 2022
commit b52411241f7f76d28a2636b776f784c5e4cdac65
10 changes: 5 additions & 5 deletions tests/Database/DatabaseEloquentCollectionQueueableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Mockery;
use Mockery as m;
driesvints marked this conversation as resolved.
Show resolved Hide resolved
use PHPUnit\Framework\TestCase;

class DatabaseEloquentCollectionQueueableTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
m::close();
}

public function testSerializesPivotsEntitiesId()
{
$spy = Mockery::spy(Pivot::class);
$spy = m::spy(Pivot::class);

$c = new Collection([$spy]);

Expand All @@ -30,7 +30,7 @@ public function testSerializesPivotsEntitiesId()

public function testSerializesModelEntitiesById()
{
$spy = Mockery::spy(Model::class);
$spy = m::spy(Model::class);

$c = new Collection([$spy]);

Expand All @@ -49,7 +49,7 @@ public function testJsonSerializationOfCollectionQueueableIdsWorks()
// When the ID of a Model is binary instead of int or string, the Collection
// serialization + JSON encoding breaks because of UTF-8 issues. Encoding
// of a QueueableCollection must favor QueueableEntity::queueableId().
$mock = Mockery::mock(Model::class, [
$mock = m::mock(Model::class, [
'getKey' => random_bytes(10),
'getQueueableId' => 'mocked',
]);
Expand Down
10 changes: 5 additions & 5 deletions tests/Database/DatabaseEloquentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Illuminate\Database\Eloquent\Factories\Sequence;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Tests\Database\Fixtures\Models\Money\Price;
use Mockery;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class DatabaseEloquentFactoryTest extends TestCase
Expand All @@ -24,7 +24,7 @@ protected function setUp(): void
$container->singleton(Generator::class, function ($app, $parameters) {
return \Faker\Factory::create('en_US');
});
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');

$db = new DB;
Expand Down Expand Up @@ -89,7 +89,7 @@ public function createSchema()
*/
protected function tearDown(): void
{
Mockery::close();
m::close();

$this->schema()->drop('users');

Expand Down Expand Up @@ -472,7 +472,7 @@ public function test_resolve_nested_model_factories()

public function test_resolve_nested_model_name_from_factory()
{
Container::getInstance()->instance(Application::class, $app = Mockery::mock(Application::class));
Container::getInstance()->instance(Application::class, $app = m::mock(Application::class));
$app->shouldReceive('getNamespace')->andReturn('Illuminate\\Tests\\Database\\Fixtures\\');

Factory::useNamespace('Illuminate\\Tests\\Database\\Fixtures\\Factories\\');
Expand All @@ -484,7 +484,7 @@ public function test_resolve_nested_model_name_from_factory()

public function test_resolve_non_app_nested_model_factories()
{
Container::getInstance()->instance(Application::class, $app = Mockery::mock(Application::class));
Container::getInstance()->instance(Application::class, $app = m::mock(Application::class));
$app->shouldReceive('getNamespace')->andReturn('Foo\\');

Factory::useNamespace('Factories\\');
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Illuminate\Pagination\CursorPaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
use Mockery;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class DatabaseEloquentSoftDeletesIntegrationTest extends TestCase
Expand Down Expand Up @@ -212,7 +212,7 @@ public function testForceDeleteDoesntUpdateExistsPropertyIfFailed()

public function newModelQuery()
{
return Mockery::spy(parent::newModelQuery(), function (Mockery\MockInterface $mock) {
return m::spy(parent::newModelQuery(), function (Mockery\MockInterface $mock) {
$mock->shouldReceive('forceDelete')->andThrow(new Exception());
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Foundation/Testing/DatabaseMigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Mockery;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

Expand All @@ -22,7 +22,7 @@ protected function setUp(): void
'beforeApplicationDestroyed',
]);

$kernelObj = Mockery::mock();
$kernelObj = m::mock();
$kernelObj->shouldReceive('setArtisan')
->with(null);

Expand Down
4 changes: 2 additions & 2 deletions tests/Foundation/Testing/RefreshDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Mockery;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

Expand All @@ -22,7 +22,7 @@ protected function setUp(): void
'beginDatabaseTransaction',
]);

$kernelObj = Mockery::mock();
$kernelObj = m::mock();
$kernelObj->shouldReceive('setArtisan')
->with(null);

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Cookie/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Mockery;
use Mockery as m;
use Orchestra\Testbench\TestCase;

class CookieTest extends TestCase
Expand Down Expand Up @@ -45,7 +45,7 @@ protected function getEnvironmentSetUp($app)
{
$app->instance(
ExceptionHandler::class,
$handler = Mockery::mock(ExceptionHandler::class)->shouldIgnoreMissing()
$handler = m::mock(ExceptionHandler::class)->shouldIgnoreMissing()
);

$handler->shouldReceive('render')->andReturn(new Response);
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Http/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
use Illuminate\Tests\Integration\Http\Fixtures\SerializablePostResource;
use Illuminate\Tests\Integration\Http\Fixtures\Subscription;
use LogicException;
use Mockery;
use Mockery as m;
use Orchestra\Testbench\TestCase;

class ResourceTest extends TestCase
Expand Down Expand Up @@ -1156,7 +1156,7 @@ public function testPostTooLargeException()
{
$this->expectException(PostTooLargeException::class);

$request = Mockery::mock(Request::class, ['server' => ['CONTENT_LENGTH' => '2147483640']]);
$request = m::mock(Request::class, ['server' => ['CONTENT_LENGTH' => '2147483640']]);
$post = new ValidatePostSize;
$post->handle($request, function () {
});
Expand Down
16 changes: 8 additions & 8 deletions tests/Integration/Migration/MigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Illuminate\Tests\Integration\Migration;

use Illuminate\Support\Facades\DB;
use Mockery;
use Mockery as m;
use Orchestra\Testbench\TestCase;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -18,7 +18,7 @@ protected function setUp(): void
{
parent::setUp();

$this->output = Mockery::mock(OutputInterface::class);
$this->output = m::mock(OutputInterface::class);
$this->subject = $this->app->make('migrator');
$this->subject->setOutput($this->output);
$this->subject->getRepository()->createRepository();
Expand All @@ -27,11 +27,11 @@ protected function setUp(): void
public function testMigrate()
{
$this->expectOutput('<comment>Migrating:</comment> 2014_10_12_000000_create_people_table');
$this->expectOutput(Mockery::pattern('#<info>Migrated:</info> 2014_10_12_000000_create_people_table (.*)#'));
$this->expectOutput(m::pattern('#<info>Migrated:</info> 2014_10_12_000000_create_people_table (.*)#'));
$this->expectOutput('<comment>Migrating:</comment> 2015_10_04_000000_modify_people_table');
$this->expectOutput(Mockery::pattern('#<info>Migrated:</info> 2015_10_04_000000_modify_people_table (.*)#'));
$this->expectOutput(m::pattern('#<info>Migrated:</info> 2015_10_04_000000_modify_people_table (.*)#'));
$this->expectOutput('<comment>Migrating:</comment> 2016_10_04_000000_modify_people_table');
$this->expectOutput(Mockery::pattern('#<info>Migrated:</info> 2016_10_04_000000_modify_people_table (.*)#'));
$this->expectOutput(m::pattern('#<info>Migrated:</info> 2016_10_04_000000_modify_people_table (.*)#'));

$this->subject->run([__DIR__.'/fixtures']);

Expand All @@ -48,11 +48,11 @@ public function testRollback()
$this->subject->getRepository()->log('2016_10_04_000000_modify_people_table', 1);

$this->expectOutput('<comment>Rolling back:</comment> 2016_10_04_000000_modify_people_table');
$this->expectOutput(Mockery::pattern('#<info>Rolled back:</info> 2016_10_04_000000_modify_people_table (.*)#'));
$this->expectOutput(m::pattern('#<info>Rolled back:</info> 2016_10_04_000000_modify_people_table (.*)#'));
$this->expectOutput('<comment>Rolling back:</comment> 2015_10_04_000000_modify_people_table');
$this->expectOutput(Mockery::pattern('#<info>Rolled back:</info> 2015_10_04_000000_modify_people_table (.*)#'));
$this->expectOutput(m::pattern('#<info>Rolled back:</info> 2015_10_04_000000_modify_people_table (.*)#'));
$this->expectOutput('<comment>Rolling back:</comment> 2014_10_12_000000_create_people_table');
$this->expectOutput(Mockery::pattern('#<info>Rolled back:</info> 2014_10_12_000000_create_people_table (.*)#'));
$this->expectOutput(m::pattern('#<info>Rolled back:</info> 2014_10_12_000000_create_people_table (.*)#'));

$this->subject->rollback([__DIR__.'/fixtures']);

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Session/SessionPersistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Mockery;
use Mockery as m;
use Orchestra\Testbench\TestCase;

class SessionPersistenceTest extends TestCase
Expand All @@ -35,7 +35,7 @@ protected function getEnvironmentSetUp($app)
{
$app->instance(
ExceptionHandler::class,
$handler = Mockery::mock(ExceptionHandler::class)->shouldIgnoreMissing()
$handler = m::mock(ExceptionHandler::class)->shouldIgnoreMissing()
);

$handler->shouldReceive('render')->andReturn(new Response);
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Testing/ArtisanCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Illuminate\Tests\Integration\Testing;

use Illuminate\Support\Facades\Artisan;
use Mockery;
use Mockery as m;
use Mockery\Exception\InvalidCountException;
use Mockery\Exception\InvalidOrderException;
use Orchestra\Testbench\TestCase;
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function ignoringMockOnceExceptions(callable $callback)
$callback();
} finally {
try {
Mockery::close();
m::close();
} catch (InvalidCountException $e) {
// Ignore mock exception from PendingCommand::expectsOutput().
}
Expand Down
38 changes: 19 additions & 19 deletions tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Illuminate\View\Component;
use Illuminate\View\ComponentAttributeBag;
use InvalidArgumentException;
use Mockery;
use Mockery as m;

class BladeComponentTagCompilerTest extends AbstractBladeTestCase
{
protected function tearDown(): void
{
Mockery::close();
m::close();
}

public function testSlotsCanBeCompiled()
Expand Down Expand Up @@ -180,7 +180,7 @@ public function testSelfClosingComponentsCanBeCompiled()
public function testClassNamesCanBeGuessed()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
Container::setInstance($container);

Expand All @@ -194,7 +194,7 @@ public function testClassNamesCanBeGuessed()
public function testClassNamesCanBeGuessedWithNamespaces()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
Container::setInstance($container);

Expand Down Expand Up @@ -308,8 +308,8 @@ public function testPairedComponentTags()
public function testClasslessComponents()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Factory::class, $factory = Mockery::mock(Factory::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
$factory->shouldReceive('exists')->andReturn(true);
Container::setInstance($container);
Expand All @@ -327,8 +327,8 @@ public function testClasslessComponents()
public function testClasslessComponentsWithIndexView()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Factory::class, $factory = Mockery::mock(Factory::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
$factory->shouldReceive('exists')->andReturn(false, true);
Container::setInstance($container);
Expand All @@ -346,8 +346,8 @@ public function testClasslessComponentsWithIndexView()
public function testPackagesClasslessComponents()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Factory::class, $factory = Mockery::mock(Factory::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
$factory->shouldReceive('exists')->andReturn(true);
Container::setInstance($container);
Expand Down Expand Up @@ -384,8 +384,8 @@ public function __toString()
public function testItThrowsAnExceptionForNonExistingAliases()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Factory::class, $factory = Mockery::mock(Factory::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
$factory->shouldReceive('exists')->andReturn(false);
Container::setInstance($container);
Expand All @@ -398,8 +398,8 @@ public function testItThrowsAnExceptionForNonExistingAliases()
public function testItThrowsAnExceptionForNonExistingClass()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Factory::class, $factory = Mockery::mock(Factory::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
$factory->shouldReceive('exists')->andReturn(false);
Container::setInstance($container);
Expand All @@ -412,22 +412,22 @@ public function testItThrowsAnExceptionForNonExistingClass()
public function testAttributesTreatedAsPropsAreRemovedFromFinalAttributes()
{
$container = new Container;
$container->instance(Application::class, $app = Mockery::mock(Application::class));
$container->instance(Factory::class, $factory = Mockery::mock(Factory::class));
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
$factory->shouldReceive('exists')->andReturn(false);
Container::setInstance($container);

$attributes = new ComponentAttributeBag(['userId' => 'bar', 'other' => 'ok']);

$component = Mockery::mock(\Illuminate\View\Component::class);
$component = m::mock(\Illuminate\View\Component::class);
$component->shouldReceive('withName', 'test');
$component->shouldReceive('shouldRender')->andReturn(true);
$component->shouldReceive('resolveView')->andReturn('');
$component->shouldReceive('data')->andReturn([]);
$component->shouldReceive('withAttributes');

$__env = Mockery::mock(\Illuminate\View\Factory::class);
$__env = m::mock(\Illuminate\View\Factory::class);
$__env->shouldReceive('getContainer->make')->with(TestProfileComponent::class, ['userId' => 'bar', 'other' => 'ok'])->andReturn($component);
$__env->shouldReceive('startComponent');
$__env->shouldReceive('renderComponent');
Expand All @@ -446,7 +446,7 @@ public function testAttributesTreatedAsPropsAreRemovedFromFinalAttributes()
protected function mockViewFactory($existsSucceeds = true)
{
$container = new Container;
$container->instance(Factory::class, $factory = Mockery::mock(Factory::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$factory->shouldReceive('exists')->andReturn($existsSucceeds);
Container::setInstance($container);
}
Expand Down