diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..a580497 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,27 @@ +run-name: ${{ github.actor }} is running Unit Tests +on: + push: + branches: + - main + - feature/* +# pull_request: +# branches: +# - develop + +permissions: + contents: write + +jobs: + unit-test: + strategy: + matrix: + php_version: + - 8.1 + - 8.2 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: mage-os/github-actions/unit-test@main + with: + php_version: ${{ matrix.php_version }} + composer_auth: ${{ secrets.COMPOSER_AUTH }} 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) + ) + ); + } +} diff --git a/composer.json b/composer.json index 4de99cd..f4ac052 100644 --- a/composer.json +++ b/composer.json @@ -5,9 +5,18 @@ "license": [ "GPL-3.0-only" ], + "repositories": [ + { + "type": "composer", + "url": "https://mirror.mage-os.org" + } + ], "require": { "php": ">=8.1.0", - "magento/framework": "*" + "magento/module-graph-ql": "*" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" }, "autoload": { "files": [ @@ -15,6 +24,15 @@ ], "psr-4": { "MageOS\\GraphQlPlayground\\": "" - }} + } + }, + "scripts": { + "test": "phpunit" + }, + "config": { + "allow-plugins": { + "magento/composer-dependency-version-audit-plugin": false, + "magento/magento-composer-installer": false + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..34ac61a --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,15 @@ + + + + + Test/Unit + + + + + + + +