PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.11.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.11.0
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.7 2.6.8 2.6.5 2.6.4 2.6.3 2.6.2 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2.0 2.0 2.1.0 2.1.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1
reviews-feed / tests / Unit / Doubles / UsageReporterWpdbDouble.php
reviews-feed / tests / Unit / Doubles Last commit date
FeedCacheWpdbDouble.php 1 week ago UsageReporterWpdbDouble.php 1 week ago
UsageReporterWpdbDouble.php
55 lines
1 <?php
2
3 namespace SmashBalloon\Reviews\Tests\Unit\Doubles;
4
5 /**
6 * Minimal `wpdb` test double for the usage-tracking ReviewsReporter.
7 *
8 * get_var() answers the `SHOW TABLES LIKE %s` existence probe (every table
9 * exists) and get_results() returns canned feed rows, so the reporter's
10 * feed-data SQL and row-shape handling can be asserted without a live
11 * database. One class per file per PSR1.
12 */
13 class UsageReporterWpdbDouble
14 {
15 /** @var string */
16 public $prefix = 'wp_';
17
18 /** @var array<int, array<string, mixed>> */
19 public $next_results = array();
20
21 /** @var string|null */
22 public $last_get_results_sql = null;
23
24 /** @var mixed Last value handed to prepare(), i.e. the probed table name. */
25 public $last_prepared_arg = null;
26
27 /** @var int Value returned for COUNT(*) queries. */
28 public $next_count = 0;
29
30 public function prepare($sql, ...$args)
31 {
32 $this->last_prepared_arg = $args[0] ?? null;
33 return $sql;
34 }
35
36 public function get_var($sql)
37 {
38 // A COUNT(*) is a real scalar query, not the existence probe. Returning the
39 // probed table name for it would cast to (int) 0 and quietly satisfy any
40 // assertion on connected_count / feed_caches_count / reviews_count.
41 if (false !== stripos((string) $sql, 'COUNT(')) {
42 return $this->next_count;
43 }
44
45 // `SHOW TABLES LIKE` probe — report the probed table as existing.
46 return $this->last_prepared_arg;
47 }
48
49 public function get_results($sql, $output_type = 'OBJECT')
50 {
51 $this->last_get_results_sql = $sql;
52 return $this->next_results;
53 }
54 }
55