public function testBasics() { $data = ['foo' => 'bar']; $ex = new MetadataMergeException(); $this->assertInstanceOf('UnexpectedValueException', $ex); $this->assertSame([], $ex->getContext()); $ex2 = new MetadataMergeException('Message', 42, $ex, $data); $this->assertSame('Message', $ex2->getMessage()); $this->assertSame(42, $ex2->getCode()); $this->assertSame($ex, $ex2->getPrevious()); $this->assertSame($data, $ex2->getContext()); $ex->setContext($data); $this->assertSame($data, $ex->getContext()); }
/** * Merge saved session provider metadata * * The default implementation checks that anything in both arrays is * identical, then returns $providedMetadata. * * @protected For use by \\MediaWiki\\Session\\SessionManager only * @param array $savedMetadata Saved provider metadata * @param array $providedMetadata Provided provider metadata * @return array Resulting metadata * @throws MetadataMergeException If the metadata cannot be merged */ public function mergeMetadata(array $savedMetadata, array $providedMetadata) { foreach ($providedMetadata as $k => $v) { if (array_key_exists($k, $savedMetadata) && $savedMetadata[$k] !== $v) { $e = new MetadataMergeException("Key \"{$k}\" changed"); $e->setContext(['old_value' => $savedMetadata[$k], 'new_value' => $v]); throw $e; } } return $providedMetadata; }