Skip to content

Commit

Permalink
Merge pull request #1 from mage-os-lab/feature/ci-setup
Browse files Browse the repository at this point in the history
CI Setup
  • Loading branch information
cmuench authored Nov 21, 2023
2 parents 435e96f + 7eefc78 commit 50e56cf
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -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 }}
94 changes: 94 additions & 0 deletions Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

namespace MageOS\GraphQlPlayground\Test\Unit\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\State;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\ScopeInterface;
use MageOS\GraphQlPlayground\Model\Config;
use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
/**
* @var State |\PHPUnit\Framework\MockObject\MockObject
*/
private State $stateMock;

/**
* @var ScopeConfigInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private $scopeConfigMock;

/**
* @var Config
*/
private $sut;

protected function setUp(): void
{
$this->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)
)
);
}
}
22 changes: 20 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,34 @@
"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": [
"registration.php"
],
"psr-4": {
"MageOS\\GraphQlPlayground\\": ""
}}
}
},
"scripts": {
"test": "phpunit"
},
"config": {
"allow-plugins": {
"magento/composer-dependency-version-audit-plugin": false,
"magento/magento-composer-installer": false
}
}
}
15 changes: 15 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
verbose="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit Tests">
<directory>Test/Unit</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="E_ALL"/>
<ini name="display_errors" value="1"/>
<ini name="display_startup_errors" value="1"/>
</php>
</phpunit>

0 comments on commit 50e56cf

Please sign in to comment.