summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-04-10 15:24:51 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-04-14 21:21:16 +0200
commita17c5b5f05ca4c7cf4f0d0d640f95ae283b1796a (patch)
tree4ece4b944cae0316eed272a2f44b304142a4d912
parent558544fcef3335216d225bb587129a424db8d7af (diff)
downloadgigologadmin-a17c5b5f05ca4c7cf4f0d0d640f95ae283b1796a.tar.gz
gigologadmin-a17c5b5f05ca4c7cf4f0d0d640f95ae283b1796a.tar.bz2
gigologadmin-a17c5b5f05ca4c7cf4f0d0d640f95ae283b1796a.zip
Use (object) notation to create plain objects.
-rw-r--r--includes/venue.php11
-rw-r--r--tests/VenueTest.php39
2 files changed, 27 insertions, 23 deletions
diff --git a/includes/venue.php b/includes/venue.php
index 9b4a3af..896f448 100644
--- a/includes/venue.php
+++ b/includes/venue.php
@@ -1,5 +1,4 @@
<?php
-
// SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
// SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
//
@@ -30,11 +29,11 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
}
static function create($name,$city)
- { if(empty($city)) $city='Oslo';
- $attrs = new stdClass();
- $attrs->wpgvenue_name = $name;
- $attrs->wpgvenue_city = $city;
- $venue = new GiglogAdmin_Venue($attrs);
+ {
+ $venue = new GiglogAdmin_Venue((object) [
+ 'wpgvenue_name' => $name,
+ 'wpgvenue_city' => !empty($city) ? $city : 'Oslo',
+ ]);
$venue->save();
return $venue;
diff --git a/tests/VenueTest.php b/tests/VenueTest.php
index e886167..bea6dc4 100644
--- a/tests/VenueTest.php
+++ b/tests/VenueTest.php
@@ -31,19 +31,22 @@ final class VenueTest extends TestCase
{
global $wpdb;
- $v = new stdClass();
- $v->id = 42;
- $v->wpgvenue_name = 'Slarkhaillen';
- $v->wpgvenue_city = 'Ofoten';
- $v->wpgvenue_address = 'Baillsvingen 4';
- $v->wpgvenue_webpage = 'https://slarkhaillen.no';
+ $results = array(
+ (object) [
+ 'id' => 42,
+ 'wpgvenue_name' => 'Slarkhaillen',
+ 'wpgvenue_city' => 'Ofoten',
+ 'wpgvenue_address' => 'Baillsvingen 4',
+ 'wpgvenue_webpage' => 'https://slarkhaillen.no'
+ ]);
$wpdb = $this->createStub(wpdb::class);
- $wpdb->method('get_results')->willReturn(array($v));
+ $wpdb->method('get_results')->willReturn($results);
+
$venue = GiglogAdmin_Venue::find_or_create("Slarkhaillen");
- $this->assertEquals(42, $venue->id());
- $this->assertEquals($v->wpgvenue_name, $venue->name());
+ $this->assertEquals($results[0]->id, $venue->id());
+ $this->assertEquals($results[0]->wpgvenue_name, $venue->name());
}
public function testFindAllVenuesInCity() : void
@@ -52,10 +55,11 @@ final class VenueTest extends TestCase
$results = array();
for ($i = 0; $i < 3; $i++) {
- $results[$i] = new stdClass();
- $results[$i]->id = 42 + $i;
- $results[$i]->wpgvenue_name = "Venue #" . $i;
- $results[$i]->wpgvenue_city = "Osaka";
+ $results[$i] = (object) [
+ 'id' => 42 + $i,
+ 'wpgvenue_name' => "Venue #" . $i,
+ 'wpgvenue_city' => "Osaka"
+ ];
}
$wpdb = $this->createStub(wpdb::class);
@@ -77,10 +81,11 @@ final class VenueTest extends TestCase
$results = array();
for ($i = 0; $i < 3; $i++) {
- $results[$i] = new stdClass();
- $results[$i]->id = 42 + $i;
- $results[$i]->wpgvenue_name = "Venue #" . $i;
- $results[$i]->wpgvenue_city = "City #" . $i;
+ $results[$i] = (object) [
+ 'id' => 42 + $i,
+ 'wpgvenue_name' => "Venue #" . $i,
+ 'wpgvenue_city' => "City #" . $i
+ ];
}
$wpdb = $this->createStub(wpdb::class);