11<?php namespace Tests \Support ;
22
33use CodeIgniter \Test \CIDatabaseTestCase ;
4+ use CodeIgniter \Test \Fabricator ;
5+ use Config \Services ;
6+ use Tatter \Audits \Audits ;
7+ use Tests \Support \Models \WidgetModel ;
48
59class DatabaseTestCase extends CIDatabaseTestCase
610{
@@ -18,12 +22,65 @@ class DatabaseTestCase extends CIDatabaseTestCase
1822 */
1923 protected $ config ;
2024
25+ /**
26+ * Instance of the test model
27+ *
28+ * @var Tests\Support\Models\WidgetModel
29+ */
30+ protected $ model ;
31+
32+ /**
33+ * Instance of the fabricator primed with our model
34+ *
35+ * @var CodeIgniter\Test\Fabricator
36+ */
37+ protected $ fabricator ;
38+
2139 public function setUp (): void
2240 {
2341 parent ::setUp ();
2442
2543 $ config = new \Tatter \Audits \Config \Audits ();
2644 $ config ->silent = false ;
2745 $ this ->config = $ config ;
46+
47+ // Reset the service
48+ $ audits = new Audits ($ config );
49+ Services::injectMock ('audits ' , $ audits );
50+
51+ // Prep model components
52+ $ this ->model = new WidgetModel ();
53+ $ this ->fabricator = new Fabricator ($ this ->model );
54+ }
55+
56+ /**
57+ * Asserts that an audit with the given properties is in the queue
58+ *
59+ * @param array $values Array of values to confirm
60+ *
61+ * @return self
62+ */
63+ public function seeAudit (array $ values )
64+ {
65+ $ queue = service ('audits ' )->getQueue ();
66+ $ found = false ;
67+
68+ // Check each audit in the queue for a match
69+ foreach ($ queue as $ audit )
70+ {
71+ // Check each value against the audit
72+ foreach ($ values as $ key => $ value )
73+ {
74+ if ($ audit [$ key ] != $ value )
75+ {
76+ break 2 ;
77+ }
78+ }
79+
80+ $ found = true ;
81+ break ;
82+ }
83+
84+ $ this ->assertTrue ($ found , 'Audit not found in queue: ' . print_r ($ values , true ));
2885 }
2986}
0 commit comments