@@ -85,20 +85,18 @@ public function testCriteriaComposition()
8585 new OneOfSpecification ($ trueSpec , $ falseSpec , $ trueSpec ),
8686 $ trueSpec
8787 );
88- $ visitor = new Visitor ();
89- $ compositeSpec ->criteria ()->getWhereExpression ()->visit ($ visitor );
9088 $ this ->assertSame (
91- '((((((bool = 1) AND (bool = 0)) OR (bool = 1)) AND (bool = 0)) AND (((bool = 1) OR (bool = 0)) OR (bool = 1))) AND (bool = 1) ) ' ,
92- $ visitor -> trace ( )
89+ '((((1) AND (0)) OR (1)) AND (0)) AND ((1) OR (0) OR (1)) AND (1 ) ' ,
90+ $ compositeSpec -> whereExpression ( ' a ' )
9391 );
9492 }
9593
9694 /**
9795 * @expectedException \BadMethodCallException
9896 */
99- public function testCriteriaIsNotSupported ()
97+ public function testWhereExpressionIsNotSupported ()
10098 {
101- (new BoolSpecification (true ))->not ()->criteria ( );
99+ (new BoolSpecification (true ))->not ()->whereExpression ( ' a ' );
102100 }
103101}
104102
@@ -116,44 +114,8 @@ public function isSatisfiedBy($object): bool
116114 return $ this ->bool ;
117115 }
118116
119- public function criteria ( ): Criteria
117+ public function whereExpression ( string $ alias ): string
120118 {
121- return new Criteria (Criteria::expr ()->eq ('bool ' , $ this ->bool ));
122- }
123- }
124-
125- class Visitor extends ExpressionVisitor
126- {
127- private $ trace ;
128-
129- public function walkComparison (Comparison $ comparison )
130- {
131- $ this ->trace .= '( ' ;
132- $ this ->trace .= $ comparison ->getField ();
133- $ this ->trace .= ' ' . $ comparison ->getOperator () . ' ' ;
134- $ this ->trace .= $ this ->walkValue ($ comparison ->getValue ());
135- $ this ->trace .= ') ' ;
136- }
137-
138- public function walkCompositeExpression (CompositeExpression $ expr )
139- {
140- $ this ->trace .= '( ' ;
141- foreach ($ expr ->getExpressionList () as $ i => $ child ) {
142- if ($ i !== 0 ) {
143- $ this ->trace .= (' ' . $ expr ->getType () . ' ' );
144- }
145- $ expressionList [] = $ this ->dispatch ($ child );
146- }
147- $ this ->trace .= ') ' ;
148- }
149-
150- public function walkValue (Value $ value )
151- {
152- return $ value ->getValue () ? '1 ' : '0 ' ;
153- }
154-
155- public function trace ()
156- {
157- return $ this ->trace ;
119+ return $ this ->bool ? '1 ' : '0 ' ;
158120 }
159121}
0 commit comments