@@ -25,16 +25,6 @@ class CleanExpiredQuotesTest extends \PHPUnit\Framework\TestCase
25
25
*/
26
26
private $ cleanExpiredQuotes ;
27
27
28
- /**
29
- * @var QuoteRepository
30
- */
31
- private $ quoteRepository ;
32
-
33
- /**
34
- * @var SearchCriteriaBuilder
35
- */
36
- private $ searchCriteriaBuilder ;
37
-
38
28
/**
39
29
* @var QuoteCollectionFactory
40
30
*/
@@ -47,8 +37,6 @@ protected function setUp()
47
37
{
48
38
$ objectManager = Bootstrap::getObjectManager ();
49
39
$ this ->cleanExpiredQuotes = $ objectManager ->get (CleanExpiredQuotes::class);
50
- $ this ->quoteRepository = $ objectManager ->get (QuoteRepository::class);
51
- $ this ->searchCriteriaBuilder = $ objectManager ->get (SearchCriteriaBuilder::class);
52
40
$ this ->quoteCollectionFactory = $ objectManager ->get (QuoteCollectionFactory::class);
53
41
}
54
42
@@ -60,18 +48,14 @@ protected function setUp()
60
48
*/
61
49
public function testExecute ()
62
50
{
63
- $ searchCriteria = $ this ->searchCriteriaBuilder ->create ();
64
51
//Initial count - should be equal to stores number.
65
- $ this ->assertEquals ( 2 , $ this -> quoteRepository -> getList ( $ searchCriteria )-> getTotalCount () );
52
+ $ this ->assertQuotesCount ( 2 );
66
53
67
54
//Deleting expired quotes
68
55
$ this ->cleanExpiredQuotes ->execute ();
69
- $ totalCount = $ this -> quoteRepository -> getList ( $ searchCriteria )-> getTotalCount ();
56
+
70
57
//Only 1 will be deleted for the store that has all of them expired by config (default_store)
71
- $ this ->assertEquals (
72
- 1 ,
73
- $ totalCount
74
- );
58
+ $ this ->assertQuotesCount (1 );
75
59
}
76
60
77
61
/**
@@ -83,14 +67,24 @@ public function testExecute()
83
67
public function testExecuteWithBigAmountOfQuotes ()
84
68
{
85
69
//Initial count - should be equal to 1000
86
- //Use collection getSize in order to get quick result
87
- $ this ->assertEquals (1000 , $ this ->quoteCollectionFactory ->create ()->getSize ());
70
+ $ this ->assertQuotesCount (1000 );
88
71
89
72
//Deleting expired quotes
90
73
$ this ->cleanExpiredQuotes ->execute ();
91
- $ totalCount = $ this ->quoteCollectionFactory ->create ()->getSize ();
92
74
93
75
//There should be no quotes anymore
94
- $ this ->assertEquals (0 , $ totalCount );
76
+ $ this ->assertQuotesCount (0 );
77
+ }
78
+
79
+ /**
80
+ * Optimized assert quotes count
81
+ * Uses collection getSize in order to get quick result
82
+ *
83
+ * @param int $expected
84
+ */
85
+ private function assertQuotesCount (int $ expected ): void
86
+ {
87
+ $ totalCount = $ this ->quoteCollectionFactory ->create ()->getSize ();
88
+ $ this ->assertEquals ($ expected , $ totalCount );
95
89
}
96
90
}
0 commit comments