Skip to content

Commit

Permalink
Replace Codeception tests with Pest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 19, 2024
1 parent 6453330 commit 8ea0c51
Show file tree
Hide file tree
Showing 32 changed files with 218 additions and 345 deletions.
6 changes: 3 additions & 3 deletions src/templates/_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
id: 'excludeControllerActions',
cols: [
{
type: 'text',
type: 'singleline',
heading: 'Controller Action'|t('snaptcha'),
code: true,
},
Expand All @@ -160,7 +160,7 @@
id: 'allowList',
cols: [
{
type: 'text',
type: 'singleline',
heading: 'IP Address'|t('snaptcha'),
code: true,
},
Expand All @@ -181,7 +181,7 @@
id: 'denyList',
cols: [
{
type: 'text',
type: 'singleline',
heading: 'IP Address'|t('snaptcha'),
code: true,
},
Expand Down
12 changes: 0 additions & 12 deletions tests/.env

This file was deleted.

36 changes: 27 additions & 9 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
# Static Analysis
# Testing

## Static Analysis

To run static analysis on the plugin, install PHPStan and run the following command from the root of your project.
To run static analysis on the plugin,
install [PHPStan for Craft CMS](https://github.com/craftcms/phpstan) and run the
following command from the root of your project.

```shell
./vendor/bin/phpstan analyse -c vendor/putyourlightson/craft-snaptcha/phpstan.neon
./vendor/bin/phpstan analyse -c vendor/putyourlightson/craft-snaptcha/phpstan.neon --memory-limit 1G
```

# Testing
## Easy Coding Standard

To test the plugin, install Codeception, update `.env` and run the following command from the root of your project.
To run the Easy Coding Standard on the plugin,
install [ECS for Craft CMS](https://github.com/craftcms/ecs) and run the
following command from the root of your project.

```shell
./vendor/bin/codecept run -c ./vendor/putyourlightson/craft-snaptcha unit
./vendor/bin/ecs check -c vendor/putyourlightson/craft-snaptcha/ecs.php
```

Or to run a specific test.
## Pest Tests

To run Pest tests, first install [Craft Pest](https://craft-pest.com/) core as a dev dependency.

```shell
./vendor/bin/codecept run -c ./vendor/putyourlightson/craft-snaptcha unit variables/SnaptchaVariableTest:getField
composer require markhuot/craft-pest-core:^2.0.0-rc2 --dev
```

> Ensure that the database you specify in `.env` is not one that actually contains any data as it will be cleared when the tests are run.
Then run the following command from the root of your project.

```shell
php php vendor/bin/pest --test-directory=vendor/putyourlightson/craft-snaptcha/tests/pest
```

Or to run a specific test.

```shell
php php vendor/bin/pest --test-directory=vendor/putyourlightson/craft-snaptcha/tests/pest --filter=CacheRequestTest
```
34 changes: 34 additions & 0 deletions tests/TESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Test Specification

This document outlines the test specification for the Snaptcha plugin.

---

## Architecture Tests

### [Architecture](pest/Architecture/ArchitectureTest.php)

_Tests the architecture of the plugin._

![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Source code does not contain any “dump or die” statements.

## Feature Tests

### [Allowed](pest/Feature/AllowedTest.php)

_Tests whether performing actions is allowed._

![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User is not allowed when validation is enabled.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User is allowed when validation is disabled.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User IP is allowed when in the allow list.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User IP is allowed when in a nested array in the allow list.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User IP is not allowed when not in the allow list.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User IP is denied when in the deny list.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User IP is denied when in a nested array in the deny list.
![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) User IP is not denied when not in the deny list.

### [SnaptchaVariable](pest/Feature/SnaptchaVariableTest.php)

_Tests the markup generated by the Snaptcha variable._

![Pass](https://raw.githubusercontent.com/putyourlightson/craft-generate-test-spec/main/icons/pass.svg) Field is named after field name setting.
26 changes: 0 additions & 26 deletions tests/_bootstrap.php

This file was deleted.

15 changes: 0 additions & 15 deletions tests/_craft/config/db.php

This file was deleted.

17 changes: 0 additions & 17 deletions tests/_craft/config/general.php

This file was deleted.

5 changes: 0 additions & 5 deletions tests/_craft/config/test.php

This file was deleted.

2 changes: 0 additions & 2 deletions tests/_craft/storage/.gitignore

This file was deleted.

Empty file removed tests/_data/.gitkeep
Empty file.
2 changes: 0 additions & 2 deletions tests/_output/.gitignore

This file was deleted.

26 changes: 0 additions & 26 deletions tests/_support/AcceptanceTester.php

This file was deleted.

26 changes: 0 additions & 26 deletions tests/_support/FunctionalTester.php

This file was deleted.

10 changes: 0 additions & 10 deletions tests/_support/Helper/Acceptance.php

This file was deleted.

10 changes: 0 additions & 10 deletions tests/_support/Helper/Functional.php

This file was deleted.

10 changes: 0 additions & 10 deletions tests/_support/Helper/Unit.php

This file was deleted.

26 changes: 0 additions & 26 deletions tests/_support/UnitTester.php

This file was deleted.

2 changes: 0 additions & 2 deletions tests/_support/_generated/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions tests/acceptance.suite.yml

This file was deleted.

1 change: 0 additions & 1 deletion tests/acceptance/_bootstrap.php

This file was deleted.

13 changes: 0 additions & 13 deletions tests/functional.suite.yml

This file was deleted.

1 change: 0 additions & 1 deletion tests/functional/_bootstrap.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/pest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/test-results.xml
9 changes: 9 additions & 0 deletions tests/pest/Architecture/ArchitectureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Tests the architecture of the plugin.
*/

test('Source code does not contain any “dump or die” statements')
->expect(['var_dump', 'die'])
->not->toBeUsed();
Loading

0 comments on commit 8ea0c51

Please sign in to comment.