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] Use get methods to access application locale #44521

Merged
merged 2 commits into from
Oct 9, 2022
Merged

[9.x] Use get methods to access application locale #44521

merged 2 commits into from
Oct 9, 2022

Conversation

abenevaut
Copy link
Contributor

@abenevaut abenevaut commented Oct 9, 2022

This PR allows to easily mock access to config (app.locale & app.fallback_locale) in TranslationServiceProvider.

I got this error

Error: Cannot use object of type Mockery_0_stdClass as array

/vendor/laravel/framework/src/Illuminate/Translation/TranslationServiceProvider.php:25

When I apply similar mock as https://github.com/laravel/framework/blob/9.x/tests/Foundation/FoundationApplicationTest.php#L22

class CommandTest extends TestCase
{
    protected Application $app;

    protected function setUp(): void
    {
        $this->app = new Application();
        $this->app['config'] = m::mock(\stdClass::class);
        $this->app['env'] = 'testing';

        $this->app->register(ValidationServiceProvider::class);
        $this->app->register(TranslationServiceProvider::class);
        $this->app->register(FilesystemServiceProvider::class);

        $this->app->instance('path.config', __DIR__ . '/../config');
        $this->app->instance('path.storage', __DIR__ . '/../storage');
        $this->app->instance('path.lang', __DIR__ . '/../lang');

        $this->app->boot();

        $this
            ->app['config']
            ->shouldReceive('get')
            ->once()
            ->with('app.locale')
            ->andReturns('en');
        $this
            ->app['config']
            ->shouldReceive('get')
            ->once()
            ->with('app.fallback_locale')
            ->andReturns('en');

        Facade::setFacadeApplication($this->app);
    }

@abenevaut abenevaut marked this pull request as ready for review October 9, 2022 09:42
@abenevaut abenevaut changed the title Use get method to access config for application locale Use get methods to access application locale Oct 9, 2022
@taylorotwell taylorotwell merged commit 0fbbbf2 into laravel:9.x Oct 9, 2022
@abenevaut abenevaut deleted the fix-access-config-translation-service-provider branch October 9, 2022 14:42
@GrahamCampbell GrahamCampbell changed the title Use get methods to access application locale [9.x] Use get methods to access application locale Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants