Skip to content

Commit d77b521

Browse files
committed
First pass at GitHub action to automate tests
1 parent fa34ce8 commit d77b521

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed

.env.dist.testing

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
CONVERTKIT_API_KEY_NO_DATA=
2-
CONVERTKIT_API_SECRET_NO_DATA=
3-
CONVERTKIT_API_KEY=
4-
CONVERTKIT_API_SECRET=
51
CONVERTKIT_API_FORM_NAME="Page Form"
62
CONVERTKIT_API_FORM_ID="2765139"
73
CONVERTKIT_API_FORM_FORMAT_MODAL_NAME="Modal Form"
@@ -33,4 +29,4 @@ CONVERTKIT_API_COMMERCE_JS_URL="https://cheerful-architect-3237.ck.page/commerce
3329
CONVERTKIT_API_BROADCAST_FIRST_URL="https://cheerful-architect-3237.ck.page/posts/paid-subscriber-broadcast"
3430
CONVERTKIT_API_BROADCAST_FIRST_TITLE="Paid Subscriber Broadcast"
3531
CONVERTKIT_API_BROADCAST_SECOND_URL="https://cheerful-architect-3237.ck.page/posts/broadcast-2"
36-
CONVERTKIT_API_BROADCAST_SECOND_TITLE="Broadcast 2"
32+
CONVERTKIT_API_BROADCAST_SECOND_TITLE="Broadcast 2"

.github/workflows/tests.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Run Tests
2+
3+
# When to run tests.
4+
on:
5+
pull_request:
6+
types:
7+
- opened
8+
- synchronize
9+
push:
10+
branches:
11+
- main
12+
13+
jobs:
14+
tests:
15+
# Name.
16+
name: PHP ${{ matrix.php-versions }}
17+
18+
# Virtual Environment to use.
19+
# @see: https://github.com/actions/virtual-environments
20+
runs-on: ubuntu-latest
21+
22+
# Defines PHP Versions matrix to run tests on
23+
strategy:
24+
matrix:
25+
php-versions: [ '7.4', '8.0', '8.1', '8.2' ]
26+
27+
# Steps to install, configure and run tests
28+
steps:
29+
# Checkout (copy) this repository's Plugin to this VM.
30+
- name: Checkout Code
31+
uses: actions/checkout@v3
32+
33+
# Install PHP version
34+
- name: Install PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: ${{ matrix.php-versions }}
38+
coverage: none
39+
40+
# Write any secrets, such as API keys, to the .env.dist.testing file now.
41+
# Make sure your committed .env.dist.testing file ends with a newline.
42+
# The formatting of the contents to include a blank newline is deliberate.
43+
- name: Define GitHub Secrets in .env.dist.testing
44+
uses: DamianReeves/[email protected]
45+
with:
46+
path: .env.dist.testing
47+
contents: |
48+
49+
CONVERTKIT_API_KEY=${{ secrets.CONVERTKIT_API_KEY }}
50+
CONVERTKIT_API_SECRET=${{ secrets.CONVERTKIT_API_SECRET }}
51+
CONVERTKIT_API_KEY_NO_DATA=${{ secrets.CONVERTKIT_API_KEY_NO_DATA }}
52+
CONVERTKIT_API_SECRET_NO_DATA=${{ secrets.CONVERTKIT_API_SECRET_NO_DATA }}
53+
write-mode: append
54+
55+
# Rename .env.dist.testing to .env, so PHPUnit reads it for tests.
56+
- name: Rename .env.dist.testing to .env
57+
run: mv .env.dist.testing .env
58+
59+
# Installs PHPUnit, PHP CodeSniffer and anything else needed to run tests.
60+
- name: Run Composer
61+
run: composer update
62+
63+
# Generate autoloader
64+
- name: Build PHP Autoloader
65+
run: composer dump-autoload
66+
67+
# Run Coding Standards on Tests.
68+
- name: Run Coding Standards on Tests
69+
run: php vendor/bin/phpcs --standard=phpcs.tests.xml
70+
71+
# Run PHPUnit Tests.
72+
- name: Run PHPUnit Tests
73+
run: vendor/bin/phpunit --verbose --stop-on-failure

tests/ConvertKitAPITest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class ConvertKitAPITest extends TestCase
2424
*/
2525
protected function setUp(): void
2626
{
27-
2827
// Load environment credentials from root folder.
2928
$dotenv = Dotenv\Dotenv::createImmutable(dirname(dirname(__FILE__)));
3029
$dotenv->load();
@@ -59,7 +58,7 @@ public function testGetAccount()
5958
$result = $this->api->get_account();
6059
$this->assertInstanceOf('stdClass', $result);
6160

62-
// Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10
61+
// Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
6362
$result = get_object_vars($result);
6463
$this->assertArrayHasKey('name', $result);
6564
$this->assertArrayHasKey('plan_type', $result);

0 commit comments

Comments
 (0)