55namespace Barryvdh \LaravelIdeHelper \Tests ;
66
77use Barryvdh \LaravelIdeHelper \Method ;
8- use Illuminate \Database \Eloquent \Builder ;
8+ use Illuminate \Database \Eloquent \Builder as EloquentBuilder ;
9+ use Illuminate \Database \Query \Builder as QueryBuilder ;
910use PHPUnit \Framework \TestCase ;
1011
1112class MethodTest extends TestCase
@@ -54,11 +55,11 @@ public function testOutput()
5455 }
5556
5657 /**
57- * Test the output of a class
58+ * Test the output of Illuminate\Database\Eloquent\Builder
5859 */
5960 public function testEloquentBuilderOutput ()
6061 {
61- $ reflectionClass = new \ReflectionClass (Builder ::class);
62+ $ reflectionClass = new \ReflectionClass (EloquentBuilder ::class);
6263 $ reflectionMethod = $ reflectionClass ->getMethod ('upsert ' );
6364
6465 $ method = new Method ($ reflectionMethod , 'Builder ' , $ reflectionClass );
@@ -76,12 +77,75 @@ public function testEloquentBuilderOutput()
7677DOC;
7778 $ this ->assertSame ($ output , $ method ->getDocComment ('' ));
7879 $ this ->assertSame ('upsert ' , $ method ->getName ());
79- $ this ->assertSame ('\\' . Builder ::class, $ method ->getDeclaringClass ());
80+ $ this ->assertSame ('\\' . EloquentBuilder ::class, $ method ->getDeclaringClass ());
8081 $ this ->assertSame ('$values, $uniqueBy, $update ' , $ method ->getParams (true ));
8182 $ this ->assertSame (['$values ' , '$uniqueBy ' , '$update ' ], $ method ->getParams (false ));
8283 $ this ->assertSame ('$values, $uniqueBy, $update = null ' , $ method ->getParamsWithDefault (true ));
8384 $ this ->assertSame (['$values ' , '$uniqueBy ' , '$update = null ' ], $ method ->getParamsWithDefault (false ));
8485 $ this ->assertTrue ($ method ->shouldReturn ());
86+ $ this ->assertSame ('int ' , rtrim ($ method ->getReturnTag ()->getType ()));
87+ }
88+
89+ /**
90+ * Test normalized return type of Illuminate\Database\Eloquent\Builder
91+ */
92+ public function testEloquentBuilderNormalizedReturnType ()
93+ {
94+ $ reflectionClass = new \ReflectionClass (EloquentBuilder::class);
95+ $ reflectionMethod = $ reflectionClass ->getMethod ('where ' );
96+
97+ $ method = new Method ($ reflectionMethod , 'Builder ' , $ reflectionClass , null , [], [], ['$this ' => '\\' . EloquentBuilder::class . '<static> ' ]);
98+
99+ $ output = <<<'DOC'
100+ /**
101+ * Add a basic where clause to the query.
102+ *
103+ * @param (\Closure(static): mixed)|string|array|\Illuminate\Contracts\Database\Query\Expression $column
104+ * @param mixed $operator
105+ * @param mixed $value
106+ * @param string $boolean
107+ * @return \Illuminate\Database\Eloquent\Builder<static>
108+ * @static
109+ */
110+ DOC;
111+ $ this ->assertSame ($ output , $ method ->getDocComment ('' ));
112+ $ this ->assertSame ('where ' , $ method ->getName ());
113+ $ this ->assertSame ('\\' . EloquentBuilder::class, $ method ->getDeclaringClass ());
114+ $ this ->assertSame (['$column ' , '$operator ' , '$value ' , '$boolean ' ], $ method ->getParams (false ));
115+ $ this ->assertSame (['$column ' , '$operator = null ' , '$value = null ' , "\$boolean = 'and' " ], $ method ->getParamsWithDefault (false ));
116+ $ this ->assertTrue ($ method ->shouldReturn ());
117+ $ this ->assertSame ('\Illuminate\Database\Eloquent\Builder<static> ' , rtrim ($ method ->getReturnTag ()->getType ()));
118+ }
119+
120+ /**
121+ * Test normalized return type of Illuminate\Database\Query\Builder
122+ */
123+ public function testQueryBuilderNormalizedReturnType ()
124+ {
125+ $ reflectionClass = new \ReflectionClass (QueryBuilder::class);
126+ $ reflectionMethod = $ reflectionClass ->getMethod ('whereNull ' );
127+
128+ $ method = new Method ($ reflectionMethod , 'Builder ' , $ reflectionClass , null , [], [], ['$this ' => '\\' . EloquentBuilder::class . '<static> ' ]);
129+
130+ $ output = <<<'DOC'
131+ /**
132+ * Add a "where null" clause to the query.
133+ *
134+ * @param string|array|\Illuminate\Contracts\Database\Query\Expression $columns
135+ * @param string $boolean
136+ * @param bool $not
137+ * @return \Illuminate\Database\Eloquent\Builder<static>
138+ * @static
139+ */
140+ DOC;
141+
142+ $ this ->assertSame ($ output , $ method ->getDocComment ('' ));
143+ $ this ->assertSame ('whereNull ' , $ method ->getName ());
144+ $ this ->assertSame ('\\' . QueryBuilder::class, $ method ->getDeclaringClass ());
145+ $ this ->assertSame (['$columns ' , '$boolean ' , '$not ' ], $ method ->getParams (false ));
146+ $ this ->assertSame (['$columns ' , "\$boolean = 'and' " , '$not = false ' ], $ method ->getParamsWithDefault (false ));
147+ $ this ->assertTrue ($ method ->shouldReturn ());
148+ $ this ->assertSame ('\Illuminate\Database\Eloquent\Builder<static> ' , rtrim ($ method ->getReturnTag ()->getType ()));
85149 }
86150
87151 /**
0 commit comments