Skip to content

Commit 9419a7e

Browse files
committed
Reorganize test structure and fix PHPCS compliance
1 parent df02622 commit 9419a7e

9 files changed

Lines changed: 246 additions & 100 deletions

phpcs.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,4 @@
3030
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
3131
<exclude-pattern>*/includes/class-adapter.php</exclude-pattern>
3232
</rule>
33-
<rule ref="Generic.Formatting.MultipleStatementAlignment">
34-
<exclude-pattern>*/tests/*</exclude-pattern>
35-
</rule>
36-
<rule ref="WordPress.Files.FileName">
37-
<exclude-pattern>*/tests/*</exclude-pattern>
38-
</rule>
39-
<rule ref="Generic.Files.OneObjectStructurePerFile">
40-
<exclude-pattern>*/tests/*</exclude-pattern>
41-
</rule>
42-
<rule ref="Squiz.Commenting">
43-
<exclude-pattern>*/tests/*</exclude-pattern>
44-
</rule>
45-
<rule ref="WordPress.Security.EscapeOutput">
46-
<exclude-pattern>*/tests/*</exclude-pattern>
47-
</rule>
4833
</ruleset>

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
>
99
<testsuites>
1010
<testsuite name="Microsub">
11-
<directory prefix="class-test-" suffix=".php">./tests/phpunit/includes</directory>
11+
<directory prefix="class-test-" suffix=".php">./tests/phpunit/tests</directory>
1212
</testsuite>
1313
</testsuites>
1414
<coverage>

tests/phpunit/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
}
1919

2020
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
21+
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- CLI output.
2122
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
2223
exit( 1 );
2324
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Test Adapter Implementation.
4+
*
5+
* Concrete adapter implementation for testing.
6+
*
7+
* @package Microsub
8+
*/
9+
10+
namespace Microsub\Tests;
11+
12+
use Microsub\Adapter;
13+
14+
/**
15+
* Test adapter implementation for testing.
16+
*/
17+
class Test_Adapter_Implementation extends Adapter {
18+
19+
/**
20+
* Adapter identifier.
21+
*
22+
* @var string
23+
*/
24+
protected $id = 'test-adapter';
25+
26+
/**
27+
* Adapter name.
28+
*
29+
* @var string
30+
*/
31+
protected $name = 'Test Adapter';
32+
33+
/**
34+
* Get list of channels.
35+
*
36+
* @param array $channels Current channels.
37+
* @param int $user_id User ID.
38+
* @return array Channels.
39+
*/
40+
public function get_channels( $channels, $user_id ) {
41+
return array(
42+
array(
43+
'uid' => 'notifications',
44+
'name' => 'Notifications',
45+
),
46+
array(
47+
'uid' => 'default',
48+
'name' => 'Home',
49+
),
50+
);
51+
}
52+
53+
/**
54+
* Get timeline entries.
55+
*
56+
* @param array $result Current result.
57+
* @param string $channel Channel UID.
58+
* @param array $args Query args.
59+
* @return array Timeline data.
60+
*/
61+
public function get_timeline( $result, $channel, $args ) {
62+
return array(
63+
'items' => array(
64+
array(
65+
'type' => 'entry',
66+
'_id' => 'test-1',
67+
'url' => 'https://example.com/post/1',
68+
),
69+
),
70+
);
71+
}
72+
73+
/**
74+
* Get followed feeds.
75+
*
76+
* @param array $result Current result.
77+
* @param string $channel Channel UID.
78+
* @param int $user_id User ID.
79+
* @return array Feeds.
80+
*/
81+
public function get_following( $result, $channel, $user_id ) {
82+
return array(
83+
array(
84+
'type' => 'feed',
85+
'url' => 'https://example.com/feed',
86+
),
87+
);
88+
}
89+
90+
/**
91+
* Follow a URL.
92+
*
93+
* @param array|null $result Current result.
94+
* @param string $channel Channel UID.
95+
* @param string $url URL to follow.
96+
* @param int $user_id User ID.
97+
* @return array Feed data.
98+
*/
99+
public function follow( $result, $channel, $url, $user_id ) {
100+
return array(
101+
'type' => 'feed',
102+
'url' => $url,
103+
);
104+
}
105+
106+
/**
107+
* Unfollow a URL.
108+
*
109+
* @param bool|null $result Current result.
110+
* @param string $channel Channel UID.
111+
* @param string $url URL to unfollow.
112+
* @param int $user_id User ID.
113+
* @return bool True on success.
114+
*/
115+
public function unfollow( $result, $channel, $url, $user_id ) {
116+
return true;
117+
}
118+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Test Second Adapter.
4+
*
5+
* Second adapter for multi-adapter testing.
6+
*
7+
* @package Microsub
8+
*/
9+
10+
namespace Microsub\Tests;
11+
12+
use Microsub\Adapter;
13+
14+
/**
15+
* Second test adapter for multi-adapter testing.
16+
*/
17+
class Test_Second_Adapter extends Adapter {
18+
19+
/**
20+
* Adapter identifier.
21+
*
22+
* @var string
23+
*/
24+
protected $id = 'second-adapter';
25+
26+
/**
27+
* Adapter name.
28+
*
29+
* @var string
30+
*/
31+
protected $name = 'Second Adapter';
32+
33+
/**
34+
* Get list of channels.
35+
*
36+
* @param array $channels Current channels.
37+
* @param int $user_id User ID.
38+
* @return array Channels.
39+
*/
40+
public function get_channels( $channels, $user_id ) {
41+
$channels[] = array(
42+
'uid' => 'second-channel',
43+
'name' => 'Second Channel',
44+
);
45+
return $channels;
46+
}
47+
48+
/**
49+
* Get timeline entries.
50+
*
51+
* @param array $result Current result.
52+
* @param string $channel Channel UID.
53+
* @param array $args Query args.
54+
* @return array Timeline data.
55+
*/
56+
public function get_timeline( $result, $channel, $args ) {
57+
return $result;
58+
}
59+
60+
/**
61+
* Get followed feeds.
62+
*
63+
* @param array $result Current result.
64+
* @param string $channel Channel UID.
65+
* @param int $user_id User ID.
66+
* @return array Feeds.
67+
*/
68+
public function get_following( $result, $channel, $user_id ) {
69+
return $result;
70+
}
71+
72+
/**
73+
* Follow a URL.
74+
*
75+
* @param array|null $result Current result.
76+
* @param string $channel Channel UID.
77+
* @param string $url URL to follow.
78+
* @param int $user_id User ID.
79+
* @return array|null Result.
80+
*/
81+
public function follow( $result, $channel, $url, $user_id ) {
82+
return $result;
83+
}
84+
85+
/**
86+
* Unfollow a URL.
87+
*
88+
* @param bool|null $result Current result.
89+
* @param string $channel Channel UID.
90+
* @param string $url URL to unfollow.
91+
* @param int $user_id User ID.
92+
* @return bool|null Result.
93+
*/
94+
public function unfollow( $result, $channel, $url, $user_id ) {
95+
return $result;
96+
}
97+
}

0 commit comments

Comments
 (0)