-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from tito10047/tests
Tests
- Loading branch information
Showing
15 changed files
with
395 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: "Tests" | ||
|
||
on: | ||
pull_request: | ||
push: | ||
schedule: | ||
- cron: '* 8 * * *' | ||
|
||
jobs: | ||
compatibility: | ||
name: "Tests" | ||
|
||
runs-on: ${{ matrix.operating-system }} | ||
|
||
strategy: | ||
matrix: | ||
dependencies: | ||
- "lowest" | ||
- "highest" | ||
php-version: | ||
- "8.1" | ||
- "8.2" | ||
- "8.3" | ||
- "8.4" | ||
operating-system: | ||
- "ubuntu-latest" | ||
- "windows-latest" | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v3" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "pcov" | ||
php-version: "${{ matrix.php-version }}" | ||
ini-values: memory_limit=-1 | ||
|
||
- name: "Cache dependencies" | ||
uses: "actions/cache@v3" | ||
with: | ||
path: | | ||
~/.composer/cache | ||
vendor | ||
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" | ||
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" | ||
|
||
- name: "Install lowest dependencies" | ||
if: ${{ matrix.dependencies == 'lowest' }} | ||
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" | ||
|
||
- name: "Install highest dependencies" | ||
if: ${{ matrix.dependencies == 'highest' }} | ||
run: "composer update --no-interaction --no-progress --no-suggest" | ||
|
||
- name: "Install locked dependencies" | ||
if: ${{ matrix.dependencies == 'locked' }} | ||
run: "composer install --no-interaction --no-progress --no-suggest" | ||
|
||
- name: "Tests" | ||
run: "composer test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor | ||
composer.lock | ||
tools/ | ||
tools/ | ||
/.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
> | ||
<testsuites> | ||
<testsuite name="Ace Bundle Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Huluti\AltchaBundle\Service; | ||
|
||
use AltchaOrg\Altcha\Altcha; | ||
use AltchaOrg\Altcha\Challenge; | ||
use AltchaOrg\Altcha\ChallengeOptions; | ||
|
||
class ChallengeResolver implements ChallengeResolverInterface | ||
{ | ||
|
||
public function __construct( | ||
private readonly string $hmacKey, | ||
private readonly string $expires, | ||
) | ||
{ | ||
} | ||
|
||
public function getChallenge(): Challenge | ||
{ | ||
$options = new ChallengeOptions([ | ||
'hmacKey' => $this->hmacKey, | ||
'maxNumber' => 100000, | ||
'expires' => (new \DateTime())->modify($this->expires), | ||
]); | ||
return Altcha::createChallenge($options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Huluti\AltchaBundle\Service; | ||
|
||
use AltchaOrg\Altcha\Challenge; | ||
|
||
interface ChallengeResolverInterface | ||
{ | ||
public function getChallenge(): Challenge; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Huluti\AltchaBundle\Tests; | ||
|
||
use Huluti\AltchaBundle\DependencyInjection\Compiler\HulutiAltchaBundleCompilerPass; | ||
use Huluti\AltchaBundle\HulutiAltchaBundle; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class AltchaBundleTest extends TestCase | ||
{ | ||
public function testBuild(): void | ||
{ | ||
$container = new ContainerBuilder(); | ||
$bundle = new HulutiAltchaBundle(); | ||
$bundle->build($container); | ||
|
||
$this->assertNotEmpty(array_filter( | ||
$container->getCompilerPassConfig()->getPasses(), | ||
function ($value) { | ||
return $value instanceof HulutiAltchaBundleCompilerPass; | ||
} | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Huluti\AltchaBundle\Tests\Controller; | ||
|
||
use AltchaOrg\Altcha\Altcha; | ||
use AltchaOrg\Altcha\ChallengeOptions; | ||
use Huluti\AltchaBundle\Controller\HulutiAltchaChallengeController; | ||
use Huluti\AltchaBundle\Service\ChallengeResolverInterface; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
class HulutiAltchaChallengeControllerTest extends KernelTestCase | ||
{ | ||
|
||
public function testChallenge() | ||
{ | ||
|
||
$challengeOptions = new ChallengeOptions([ | ||
'hmacKey' => 'test-key', | ||
'maxNumber' => 100000, | ||
'number' => 10, | ||
'expires' => (new \DateTime())->modify("+1 day"), | ||
]); | ||
$challenge = Altcha::createChallenge($challengeOptions); | ||
|
||
$challengeResolver = $this->createMock(ChallengeResolverInterface::class); | ||
$challengeResolver->method('getChallenge')->willReturn($challenge); | ||
|
||
$controller = new HulutiAltchaChallengeController($challengeResolver); | ||
|
||
$response = $controller->challenge(); | ||
|
||
$this->assertInstanceOf(JsonResponse::class, $response); | ||
|
||
$payload = json_decode($response->getContent(), true); | ||
|
||
$payload['number'] = 10; | ||
|
||
$isValid = Altcha::verifySolution($payload, 'test-key'); | ||
|
||
$this->assertTrue($isValid); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Huluti\AltchaBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Huluti\AltchaBundle\DependencyInjection\Compiler\HulutiAltchaBundleCompilerPass; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class TwigFormPassTest extends TestCase | ||
{ | ||
public function testProcessHasNotTwigFormResources(): void | ||
{ | ||
$container = $this->createMock(ContainerBuilder::class); | ||
$container->expects($this->once())->method('hasParameter') | ||
->with('twig.form.resources')->willReturn(false); | ||
|
||
$container->expects($this->never())->method('setParameter'); | ||
|
||
$compiler = new HulutiAltchaBundleCompilerPass(); | ||
$compiler->process($container); | ||
} | ||
|
||
public function testProcessHasTwigFormResources(): void | ||
{ | ||
$container = new ContainerBuilder(); | ||
$container->setParameter('twig.form.resources', ['foo']); | ||
|
||
$compiler = new HulutiAltchaBundleCompilerPass(); | ||
$compiler->process($container); | ||
|
||
$this->assertSame( | ||
['@HulutiAltcha/fields.html.twig', 'foo'], | ||
$container->getParameter('twig.form.resources') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Huluti\AltchaBundle\Tests\DependencyInjection; | ||
|
||
use Huluti\AltchaBundle\DependencyInjection\Configuration; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Config\Definition\Processor; | ||
|
||
class ConfigurationTest extends TestCase | ||
{ | ||
public function testProcessConfiguration(): void | ||
{ | ||
$configuration = new Configuration(); | ||
$processor = new Processor(); | ||
$config = $processor->processConfiguration($configuration, [ | ||
'huluti_altcha' => [ | ||
'hmacKey' => 'test', | ||
], | ||
]); | ||
|
||
$this->assertArrayHasKey('enable', $config); | ||
$this->assertTrue($config['enable']); | ||
|
||
$this->assertArrayHasKey('floating', $config); | ||
$this->assertFalse($config['floating']); | ||
|
||
$this->assertArrayHasKey('use_stimulus', $config); | ||
$this->assertNull($config['use_stimulus']); | ||
|
||
$this->assertArrayHasKey('hide_logo', $config); | ||
$this->assertFalse($config['hide_logo']); | ||
|
||
$this->assertArrayHasKey('hide_footer', $config); | ||
$this->assertFalse($config['hide_footer']); | ||
|
||
$this->assertArrayHasKey('altcha_js_path', $config); | ||
$this->assertIsString($config['altcha_js_path']); | ||
|
||
$this->assertArrayHasKey('hmacKey', $config); | ||
$this->assertNotNull($config['hmacKey']); | ||
|
||
} | ||
} |
Oops, something went wrong.