From 73e17817ade86739e236eef43ff2757fdc976326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Mon, 6 Nov 2023 18:05:46 +0100 Subject: [PATCH] Add Unit Test to test the test setup --- Test/Unit/Model/ConfigTest.php | 94 ++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Test/Unit/Model/ConfigTest.php diff --git a/Test/Unit/Model/ConfigTest.php b/Test/Unit/Model/ConfigTest.php new file mode 100644 index 0000000..464db96 --- /dev/null +++ b/Test/Unit/Model/ConfigTest.php @@ -0,0 +1,94 @@ +stateMock = $this->createMock(State::class); + $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class); + + $this->sut = new Config( + $this->stateMock, + $this->scopeConfigMock, + ); + } + + public function testIsEnabledInDeveloperMode(): void + { + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_DEVELOPER); + + $this->scopeConfigMock->expects($this->never())->method('isSetFlag'); + + $this->assertTrue( + $this->sut->isEnabled( + $this->createMock(StoreInterface::class) + ) + ); + } + + public function testIfIsEnabledBySettingTheRightConfig() + { + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_PRODUCTION); + + $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with( + 'dev/graphiql/enabled_in_production', + ScopeInterface::SCOPE_STORE, + $this->createMock(StoreInterface::class) + )->willReturn(true); + + $this->assertTrue( + $this->sut->isEnabled( + $this->createMock(StoreInterface::class) + ) + ); + } + + public function testIfIsDisabledBySettingTheRightConfig() + { + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_PRODUCTION); + + $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with( + 'dev/graphiql/enabled_in_production', + ScopeInterface::SCOPE_STORE, + $this->createMock(StoreInterface::class) + )->willReturn(false); + + $this->assertFalse( + $this->sut->isEnabled( + $this->createMock(StoreInterface::class) + ) + ); + } +}