Skip to content

Commit

Permalink
Merge pull request #1759 from datengraben/datengraben/apply-phpcbf-to…
Browse files Browse the repository at this point in the history
…-tests

Apply phpcbf to tests directory
  • Loading branch information
hansmorb authored Feb 7, 2025
2 parents cf577a1 + a11ead9 commit 49632b1
Show file tree
Hide file tree
Showing 69 changed files with 3,909 additions and 3,491 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# .git-blame-ignore-revs
# Apply phpcbf to entire codebase
59340f68fb9c6d6e680ac3ad40a3d095e98837a6

# Apply phpcbf to php tests code
9f0bd0de52d5dca442317c14867be7702e1a7c73
62 changes: 60 additions & 2 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,66 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https:
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<exclude name="Squiz.Commenting.FileComment" />
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />

<exclude-pattern>tests/</exclude-pattern>
</rule>


<!--
#############################################################################
Global exclusions for tests.
Copied from https://github.com/polylang/polylang/blob/master/phpcs.xml.dist
#############################################################################
-->

<rule ref="Generic.Commenting.Fixme.CommentFound">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Generic.Files.OneObjectStructurePerFile.MultipleFound">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Generic.PHP.NoSilencedErrors.Forbidden">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.Commenting.ClassComment.Missing">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.Commenting.FileComment">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.Commenting.FunctionComment.MissingParamComment">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.Commenting.VariableComment.Missing">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.PHP.CommentedOutCode.Found">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid">
<exclude-pattern>*/tests/phpunit/includes/testcase-trait.php</exclude-pattern>
</rule>

<rule ref="WordPress.NamingConventions.ValidHookName.UseUnderscores">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="WordPress.PHP.NoSilencedErrors.Discouraged">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<rule ref="WordPress.Security">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<!-- Adds commonsbooking specific wrappers around wp_kses ... -->
Expand Down
1 change: 0 additions & 1 deletion tests/php/API/AvailabilityRouteEmptyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ public function testsEmptyAvailabilitySuccess() {

$this->assertSame( 200, $response->get_status() );
$this->assertSame( 0, count( $response->get_data()->availability ) );

}
}
68 changes: 37 additions & 31 deletions tests/php/API/AvailabilityRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class AvailabilityRouteTest extends CB_REST_Route_UnitTestCase {

const USER_ID = 1;
const CURRENT_DATE = '2021-05-21';
const USER_ID = 1;
const CURRENT_DATE = '2021-05-21';
protected $ENDPOINT = '/commonsbooking/v1/availability';
private array $locationIds;
private array $itemIds;
Expand All @@ -19,22 +19,22 @@ class AvailabilityRouteTest extends CB_REST_Route_UnitTestCase {
private $locationId;
private $itemId;

public function setUp() : void {
public function setUp(): void {
parent::setUp();

// TODO creates initial data (should be mocked in the future)
ClockMock::freeze( new \DateTime( self::CURRENT_DATE ) );

// Create location
$this->locationId = self::createLocation('Testlocation', 'publish');
$this->locationId = self::createLocation( 'Testlocation', 'publish' );

// Create Item
$this->itemId = self::createItem('TestItem', 'publish');
$this->itemId = self::createItem( 'TestItem', 'publish' );

$mocked = new \DateTimeImmutable( self::CURRENT_DATE );

$start = $mocked->modify( '-1 days');
$end = $mocked->modify( '+1 days');
$start = $mocked->modify( '-1 days' );
$end = $mocked->modify( '+1 days' );

$this->createTimeframe(
$this->locationId,
Expand Down Expand Up @@ -85,27 +85,29 @@ protected function createTimeframe(
$repetitionStart,
$repetitionEnd,
$type = Timeframe::BOOKABLE_ID,
$fullday = "on",
$fullday = 'on',
$repetition = 'w',
$grid = 0,
$startTime = '8:00 AM',
$endTime = '12:00 PM',
$postStatus = 'publish',
$weekdays = [ "1", "2", "3", "4", "5", "6", "7" ],
$weekdays = [ '1', '2', '3', '4', '5', '6', '7' ],
$postAuthor = self::USER_ID,
$maxDays = 3,
$advanceBookingDays = 30,
$showBookingCodes = "on",
$createBookingCodes = "on",
$showBookingCodes = 'on',
$createBookingCodes = 'on',
$postTitle = 'TestTimeframe'
) {
// Create Timeframe
$timeframeId = wp_insert_post( [
'post_title' => $postTitle,
'post_type' => Timeframe::$postType,
'post_status' => $postStatus,
'post_author' => $postAuthor
] );
$timeframeId = wp_insert_post(
[
'post_title' => $postTitle,
'post_type' => Timeframe::$postType,
'post_status' => $postStatus,
'post_author' => $postAuthor,
]
);

update_post_meta( $timeframeId, 'type', $type );
update_post_meta( $timeframeId, 'location-id', $locationId );
Expand Down Expand Up @@ -133,32 +135,36 @@ protected function createTimeframe(
return $timeframeId;
}

public function createLocation($title, $postStatus, $admins = []) {
$locationId = wp_insert_post( [
'post_title' => $title,
'post_type' => Location::$postType,
'post_status' => $postStatus
] );
public function createLocation( $title, $postStatus, $admins = [] ) {
$locationId = wp_insert_post(
[
'post_title' => $title,
'post_type' => Location::$postType,
'post_status' => $postStatus,
]
);

$this->locationIds[] = $locationId;

if (! empty($admins)) {
if ( ! empty( $admins ) ) {
update_post_meta( $locationId, COMMONSBOOKING_METABOX_PREFIX . 'location_admins', $admins );
}

return $locationId;
}

public function createItem($title, $postStatus, $admins = []) {
$itemId = wp_insert_post( [
'post_title' => $title,
'post_type' => Item::$postType,
'post_status' => $postStatus
] );
public function createItem( $title, $postStatus, $admins = [] ) {
$itemId = wp_insert_post(
[
'post_title' => $title,
'post_type' => Item::$postType,
'post_status' => $postStatus,
]
);

$this->itemIds[] = $itemId;

if (! empty($admins)) {
if ( ! empty( $admins ) ) {
update_post_meta( $itemId, COMMONSBOOKING_METABOX_PREFIX . 'item_admins', $admins );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/API/CB_REST_Route_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public function testRoute() {
$routes = $this->server->get_routes();
$this->assertArrayHasKey( $this->ENDPOINT, $routes );
}
}
}
6 changes: 3 additions & 3 deletions tests/php/API/CB_REST_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class CB_REST_UnitTestCase extends \WP_UnitTestCase {

protected $ENDPOINT;

public function setUp() : void {
public function setUp(): void {
parent::setUp();
GeoHelperTest::setUpGeoHelperMock( $this );

/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$this->server = $wp_rest_server = new \WP_REST_Server;
$this->server = $wp_rest_server = new \WP_REST_Server();

// Enables api
Settings::updateOption( 'commonsbooking_options_api', 'api-activated', 'on' );
Expand All @@ -34,4 +34,4 @@ public function setUp() : void {
// Applies hook
do_action( 'rest_api_init' );
}
}
}
2 changes: 1 addition & 1 deletion tests/php/API/GBFS/DiscoveryRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
class DiscoveryRouteTest extends CB_REST_Route_UnitTestCase {

protected $ENDPOINT = '/commonsbooking/v1/gbfs.json';
}
}
2 changes: 1 addition & 1 deletion tests/php/API/GBFS/StationInformationRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
class StationInformationRouteTest extends CB_REST_Route_UnitTestCase {

protected $ENDPOINT = '/commonsbooking/v1/station_information.json';
}
}
2 changes: 1 addition & 1 deletion tests/php/API/GBFS/StationStatusRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
class StationStatusRouteTest extends CB_REST_Route_UnitTestCase {

protected $ENDPOINT = '/commonsbooking/v1/station_status.json';
}
}
Loading

0 comments on commit 49632b1

Please sign in to comment.