@@ -40,6 +40,13 @@ public static function provideMetricToCheckIfViolationApplies(): Generator
4040 {
4141 yield 'Invalid metric ' => [Phake::mock (Metric::class), Phake::mock (ViolationsHandlerInterface::class), false ];
4242
43+ $ violationsHandler = Phake::mock (ViolationsHandlerInterface::class);
44+ $ packageMetric = Phake::mock (PackageMetric::class);
45+ Phake::when ($ packageMetric )->__call ('get ' , ['violations ' ])->thenReturn ($ violationsHandler );
46+ Phake::when ($ packageMetric )->__call ('getInstability ' , [])->thenReturn (null );
47+ Phake::when ($ packageMetric )->__call ('getDependentInstabilities ' , [])->thenReturn ([]);
48+ yield 'Instability not defined ' => [$ packageMetric , $ violationsHandler , false ];
49+
4350 $ violationsHandler = Phake::mock (ViolationsHandlerInterface::class);
4451 $ packageMetric = Phake::mock (PackageMetric::class);
4552 Phake::when ($ packageMetric )->__call ('get ' , ['violations ' ])->thenReturn ($ violationsHandler );
@@ -113,6 +120,14 @@ public function testViolationApplies(
113120 Phake::verify ($ violationsHandler )->__call ('add ' , [$ violation ]);
114121 Phake::verifyNoOtherInteractions ($ violationsHandler );
115122 $ instability = $ metric ->getInstability ();
123+
124+ if (null === $ instability ) {
125+ $ expectedDescription = 'Packages should depend in the direction of stability. ' ;
126+ self ::assertSame ($ expectedDescription , $ violation ->getDescription ());
127+ return ;
128+ }
129+ /** @var int $violatingInstabilities the inference */
130+
116131 $ violatingInstabilities = array_filter (
117132 $ metric ->getDependentInstabilities (),
118133 static fn (float $ otherInstability ): bool => $ otherInstability >= $ instability
0 commit comments