Skip to content

Commit

Permalink
Add throw support
Browse files Browse the repository at this point in the history
  • Loading branch information
HillLiu committed Apr 2, 2021
1 parent 83c9900 commit 28b169f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
}
],
"require": {
"pmvc/pmvc": "*"
"pmvc/pmvc": "*",
"pmvc-plugin/annotation": "*"
},
"minimum-stability": "dev"
}
33 changes: 33 additions & 0 deletions src/_throw.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace PMVC;

use Exception;

${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\WrapThrow';

class WrapThrow
{
public function __invoke($willThrow, $caller, $phpunit, $error = true)
{
$annotation = \PMVC\plug('annotation');
$doc = $annotation->get($caller);
$expectedException = get($doc, 'expectedException');
$expectedExceptionMessage = get($doc, 'expectedExceptionMessage');
if (!empty($expectedException)) {
$phpunit->expectException($expectedException);
}
if (!empty($expectedExceptionMessage)) {
$phpunit->expectExceptionMessage($expectedExceptionMessage);
}
if (!$error) {
$willThrow();
} else {
try {
$willThrow();
} catch (Exception $e) {
throw new PMVCUnitException($e->getMessage(), 0);
}
}
}
}

0 comments on commit 28b169f

Please sign in to comment.