/** * Invoke phramework causing NotFoundException * @covers Phramework\SystemLog\SystemLog::register */ public function testRegisterOnException() { $this->setUp(); //Force URI route $_SERVER['REQUEST_URI'] = '/not_found/'; $additionalParameters = (object) ['API' => 'phpunit']; $this->systemLog->register($additionalParameters); $that = $this; //Use a callback to copy $step and $object arguments from ILog to this PHPUnit object \Phramework\SystemLog\APP\Log\PHPUnit::setCallback(function ($step, $object) use($that) { $that->step = $step; $that->object = $object; }); //Invoke phramework (start test) $this->phramework->invoke(); /** * Use step and object for PHPUnit tests */ $this->assertSame($this->step, StepCallback::STEP_ERROR, 'Expect STEP_AFTER_CALL_URISTRATEGY, since we dont expect any exception'); $this->assertInternalType('object', $this->object); $this->assertInternalType('integer', $this->object->request_timestamp); $this->assertInternalType('integer', $this->object->response_timestamp); $this->assertGreaterThanOrEqual($this->object->request_timestamp, $this->object->response_timestamp, 'Response timestamp must be greater or equal to request timestamp'); //Expect required keys foreach (SystemLogTest::$objectKeys as $key) { $this->assertObjectHasAttribute($key, $this->object, 'Object must have key' . $key); } $this->assertNotNull($this->object->errors, 'Must not be null, since we expect exception'); $this->assertNotNull($this->object->exception, 'Must not be null, since we expect exception'); $this->assertObjectHasAttribute('API', $this->object->additional_parameters, 'Check if additional_parameters "API" passed in object'); $this->assertSame($additionalParameters->API, $this->object->additional_parameters->API, 'Check if value of additional_parameters "API" is set correctly'); //$that->>assertEquals( // 404, // $this->object->response_status_code, // 'Status code MUST be 404, since we expect exception, caused by NotFoundException' //); }
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //Show all errors error_reporting(E_ALL); ini_set('display_errors', '1'); //This autoload path is for loading current version of phramework require __DIR__ . '/../vendor/autoload.php'; //define controller namespace, as shortcut define('NS', '\\Phramework\\Examples\\API\\Controllers\\'); use Phramework\Phramework; /** * @package examples/post * Define APP as function */ $APP = function () { //Include settings $settings = (include __DIR__ . '/../settings.php'); $URIStrategy = new \Phramework\URIStrategy\URITemplate([['book/', NS . 'BookController', 'GET', Phramework::METHOD_GET], ['book/{id}', NS . 'BookController', 'GETSingle', Phramework::METHOD_GET], ['book/', NS . 'BookController', 'POST', Phramework::METHOD_POST]]); //Initialize API $phramework = new Phramework($settings, $URIStrategy); unset($settings); Phramework::setViewer(\Phramework\Viewers\JSON::class); //Execute API $phramework->invoke(); }; /** * Execute APP */ $APP();