Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/jest-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
jest-tests:
name: Jest tests
name: Jest tests and type check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -25,6 +25,15 @@ jobs:
working-directory: packages/join-flow
run: npm test

# The type check reuses this job's install of join-flow's dependencies
# (from the root postinstall) and only adds the E2E package's.
- name: Install E2E deps
run: npm --prefix packages/join-e2e ci

# The join form and its Jest tests, the E2E tests and the fake API.
- name: Type check
run: npm run typecheck

prettier:
name: Prettier
runs-on: ubuntu-latest
Expand All @@ -41,4 +50,5 @@ jobs:
run: npm ci --ignore-scripts

- name: Check formatting
run: npx prettier --check packages/join-flow
run: npx prettier --check packages/join-flow packages/join-e2e

4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
packages/join-flow/build
packages/join-flow/dist
packages/join-flow/dist
packages/join-e2e/test-results
packages/join-e2e/playwright-report
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build": "npm --prefix packages/join-flow run build",
"dist": "npm run build && scripts/package.sh",
"deploy": "npm run build && sh scripts/deploy.sh",
"prettier": "prettier --write packages/join-flow"
"prettier": "prettier --write packages/join-flow packages/join-e2e",
"typecheck": "tsc --noEmit -p packages/join-flow && npm --prefix packages/join-e2e run typecheck"
Comment thread
conatus marked this conversation as resolved.
Resolved
},
"devDependencies": {
"prettier": "^3.9.10",
Expand Down
5 changes: 4 additions & 1 deletion packages/join-block/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<file>.</file>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>wordpress/*</exclude-pattern>
<arg name="extensions" value="php"/>

Expand All @@ -23,7 +22,11 @@
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
<exclude-pattern>src/CK_Theme_Options_Container.php</exclude-pattern>
</rule>
<!-- Snake_case method names are also allowed in tests: test doubles
mirror WordPress's APIs ($wpdb->get_results and the like), and some
tests use PHPUnit's test_snake_case names. -->
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>src/CK_Theme_Options_Container.php</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>
</ruleset>
1 change: 1 addition & 0 deletions packages/join-block/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parameters:
paths:
- src
- join.php
- tests
scanDirectories:
- vendor
- wordpress
Expand Down
11 changes: 6 additions & 5 deletions packages/join-block/tests/JoinServiceFreeMembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ public function get_results(string $query, $output = null): array
$joinBlockLog = new class {
public array $errors = [];

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info(string $msg, array $ctx = []): void {}
public function info(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning(string $msg, array $ctx = []): void {}
public function warning(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error(string $msg, array $ctx = []): void
{
$this->errors[] = $msg;
Expand Down
11 changes: 6 additions & 5 deletions packages/join-block/tests/JoinServiceMailchimpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ public function get_results(string $query, $output = null): array
$joinBlockLog = new class {
public array $errors = [];

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info(string $msg, array $ctx = []): void {}
public function info(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning(string $msg, array $ctx = []): void {}
public function warning(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error(string $msg, array $ctx = []): void
{
$this->errors[] = $msg;
Expand Down
3 changes: 0 additions & 3 deletions packages/join-block/tests/LapsingFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ protected function setUp(): void

global $joinBlockLog;
$joinBlockLog = new class {
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info($msg, $ctx = [])
{
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning($msg, $ctx = [])
{
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error($msg, $ctx = [])
{
}
Expand Down
3 changes: 0 additions & 3 deletions packages/join-block/tests/MailchimpServiceLegacyTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,16 @@ protected function setUp(): void
public array $warnings = [];
public array $errors = [];

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info(string $msg, array $ctx = []): void
{
$this->infos[] = $msg;
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning(string $msg, array $ctx = []): void
{
$this->warnings[] = $msg;
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error(string $msg, array $ctx = []): void
{
$this->errors[] = $msg;
Expand Down
11 changes: 6 additions & 5 deletions packages/join-block/tests/MailchimpServiceTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ protected function setUp(): void
$joinBlockLog = new class {
public array $errors = [];

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info(string $msg, array $ctx = []): void {}
public function info(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning(string $msg, array $ctx = []): void {}
public function warning(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error(string $msg, array $ctx = []): void
{
$this->errors[] = $msg;
Expand Down
6 changes: 3 additions & 3 deletions packages/join-block/tests/SessionLockTestProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once(__DIR__ . "/../vendor/autoload.php");

// Load WordPress functions required by JoinService::acquireLock()
define( 'ABSPATH', __DIR__ . '/../wordpress/' );
define( 'WPINC', 'wp-includes' );
define('ABSPATH', __DIR__ . '/../wordpress/');
define('WPINC', 'wp-includes');
require_once(__DIR__ . "/../wordpress/wp-includes/formatting.php");
require_once(__DIR__ . "/../wordpress/wp-includes/functions.php");

Expand All @@ -28,7 +28,7 @@
$joinBlockLogFile = fopen($joinBlockLogLocation, 'a');
$joinBlockLog->pushHandler(new StreamHandler($joinBlockLogFile, Level::Info));

$lockKey = $argv[1];
$lockKey = $_SERVER['argv'][1];

$joinBlockLog->info("Testing lock with key $lockKey");

Expand Down
5 changes: 0 additions & 5 deletions packages/join-block/tests/SettingsComputeTagsToRemoveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class SettingsComputeTagsToRemoveTest extends TestCase
/** Values returned by the carbon_get_theme_option stub, keyed by field name. */
private array $settings = [];

/** Plan rows returned by the $wpdb stub, as stored in wp_options. */
private array $storedPlans = [];

protected function setUp(): void
{
parent::setUp();
Expand All @@ -49,12 +46,10 @@ public function prepare(string $query, ...$args): string
{
return $query;
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function esc_like(string $text): string
{
return $text;
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function get_results(string $query, $output = null): array
{
return $this->rows;
Expand Down
30 changes: 24 additions & 6 deletions packages/join-block/tests/SettingsMembershipPlanLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Brain\Monkey;
use CommonKnowledge\JoinBlock\Settings;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -160,10 +159,29 @@ public function testReturnsFalsyWhenNoStoredPlanMatches(): void
private function stubWpdbWithRows(array $rows): void
{
global $wpdb;
$wpdb = Mockery::mock();
$wpdb->options = 'wp_options';
$wpdb->shouldReceive('esc_like')->andReturnUsing(fn($s) => $s);
$wpdb->shouldReceive('prepare')->andReturnUsing(fn($sql) => $sql);
$wpdb->shouldReceive('get_results')->andReturn($rows);
// A plain stub rather than a Mockery double of \wpdb: WordPress isn't
// loaded here, and mocking the class would declare an empty global wpdb.
$wpdb = new class ($rows) {
public string $options = 'wp_options';

public function __construct(private array $rows)
{
}

public function prepare(string $query, ...$args): string
{
return $query;
}

public function esc_like(string $text): string
{
return $text;
}

public function get_results(string $query, $output = null): array
{
return $this->rows;
}
};
}
}
14 changes: 8 additions & 6 deletions packages/join-block/tests/StripeInvoicePaidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ protected function setUp(): void
$joinBlockLog = new class {
public array $errors = [];

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info(string $msg, array $ctx = []): void {}
public function info(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning(string $msg, array $ctx = []): void {}
public function warning(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error(string $msg, array $ctx = []): void
{
$this->errors[] = $msg;
Expand All @@ -52,7 +53,8 @@ protected function tearDown(): void
{
global $joinBlockLog;
$joinBlockLog = null;
\Stripe\ApiRequestor::setHttpClient(null);
// Back to the client Stripe uses by default.
\Stripe\ApiRequestor::setHttpClient(\Stripe\HttpClient\CurlClient::instance());
Monkey\tearDown();
parent::tearDown();
}
Expand Down
17 changes: 10 additions & 7 deletions packages/join-block/tests/StripePriceReuseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ protected function setUp(): void

global $joinBlockLog;
$joinBlockLog = new class {
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info(string $msg, array $ctx = []): void {}
public function info(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning(string $msg, array $ctx = []): void {}
public function warning(string $msg, array $ctx = []): void
{
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error(string $msg, array $ctx = []): void {}
public function error(string $msg, array $ctx = []): void
{
}
};

\Stripe\Stripe::setApiKey('sk_test_fake');
Expand All @@ -73,7 +76,7 @@ protected function tearDown(): void
{
global $joinBlockLog;
$joinBlockLog = null;
\Stripe\ApiRequestor::setHttpClient(null);
\Stripe\ApiRequestor::setHttpClient(\Stripe\HttpClient\CurlClient::instance());
Monkey\tearDown();
parent::tearDown();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/join-block/tests/StripeWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public function testResolveTierTagChangesSharedTagsAreNotRemoved(): void
$result = $this->callResolveTierTagChanges($newPlan, $oldPlan);

$this->assertContains('high-wage', $result['addTags']);
$this->assertContains('member', $result['addTags']);
$this->assertContains('low-wage', $result['removeTags']);
$this->assertContains('member', $result['addTags']);
$this->assertContains('low-wage', $result['removeTags']);
$this->assertNotContains('member', $result['removeTags'], 'member must not be removed when it is also being added');
}

Expand Down
3 changes: 0 additions & 3 deletions packages/join-block/tests/ZetkinServiceTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ protected function setUp(): void
public array $warnings = [];
public array $errors = [];

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function info(string $msg, array $ctx = []): void
{
$this->infos[] = $msg;
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function warning(string $msg, array $ctx = []): void
{
$this->warnings[] = $msg;
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function error(string $msg, array $ctx = []): void
{
$this->errors[] = $msg;
Expand Down
5 changes: 5 additions & 0 deletions packages/join-e2e/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"printWidth": 120,
"trailingComma": "all"
}
Loading
Loading