<commit_before><?php

namespace Bugsnag\Tests;

use Bugsnag\Client;
use Bugsnag\Configuration;
use Bugsnag\Handler;
use Exception;
use PHPUnit_Framework_TestCase as TestCase;

class HandlerTest extends TestCase
{
    protected $client;

    protected function setUp()
    {
        $this->client = $this->getMockBuilder(Client::class)
                             ->setMethods(['notify'])
                             ->setConstructorArgs([new Configuration('example-api-key')])
                             ->getMock();
    }

    public function testErrorHandler()
    {
        $this->client->expects($this->once())->method('notify');

        Handler::register($this->client)->errorHandler(E_WARNING, 'Something broke', 'somefile.php', 123);
    }

    public function testExceptionHandler()
    {
        $this->client->expects($this->once())->method('notify');

        Handler::register($this->client)->exceptionHandler(new Exception('Something broke'));
    }

    public function testErrorReportingLevel()
    {
        $this->client->expects($this->once())->method('notify');

        $this->client->setErrorReportingLevel(E_NOTICE);

        Handler::register($this->client)->errorHandler(E_NOTICE, 'Something broke', 'somefile.php', 123);
    }

    public function testErrorReportingLevelFails()
    {
        $this->client->expects($this->never())->method('notify');

        $this->client->setErrorReportingLevel(E_NOTICE);

        Handler::register($this->client)->errorHandler(E_WARNING, 'Something broke', 'somefile.php', 123);
    }

    public function testErrorReportingWithoutNotice()
    {
        $this->client->expects($this->never())->method('notify');

        $this->client->setErrorReportingLevel(E_ALL & ~E_NOTICE);

        Handler::register($this->client)->errorHandler(E_NOTICE, 'Something broke', 'somefile.php', 123);
    }
}<commit_msg>Test the shutdown handler works (#265)<commit_after><?php

namespace Bugsnag\Tests;

use Bugsnag\Client;
use Bugsnag\Configuration;
use Bugsnag\Handler;
use Exception;
use phpmock\phpunit\PHPMock;
use PHPUnit_Framework_TestCase as TestCase;

class HandlerTest extends TestCase
{
    use PHPMock;

    protected $client;

    protected function setUp()
    {
        $this->client = $this->getMockBuilder(Client::class)
                             ->setMethods(['notify', 'flush'])
                             ->setConstructorArgs([new Configuration('example-api-key')])
                             ->getMock();
    }

    public function testErrorHandler()
    {
        $this->client->expects($this->once())->method('notify');

        Handler::register($this->client)->errorHandler(E_WARNING, 'Something broke', 'somefile.php', 123);
    }

    public function testExceptionHandler()
    {
        $this->client->expects($this->once())->method('notify');

        Handler::register($this->client)->exceptionHandler(new Exception('Something broke'));
    }

    public function testErrorReportingLevel()
    {
        $this->client->expects($this->once())->method('notify');

        $this->client->setErrorReportingLevel(E_NOTICE);

        Handler::register($this->client)->errorHandler(E_NOTICE, 'Something broke', 'somefile.php', 123);
    }

    public function testErrorReportingLevelFails()
    {
        $this->client->expects($this->never())->method('notify');

        $this->client->setErrorReportingLevel(E_NOTICE);

        Handler::register($this->client)->errorHandler(E_WARNING, 'Something broke', 'somefile.php', 123);
    }

    public function testErrorReportingWithoutNotice()
    {
        $this->client->expects($this->never())->method('notify');

        $this->client->setErrorReportingLevel(E_ALL & ~E_NOTICE);

        Handler::register($this->client)->errorHandler(E_NOTICE, 'Something broke', 'somefile.php', 123);
    }

    public function testCanShutdown()
    {
        $this->client->expects($this->never())->method('notify');
        $this->client->expects($this->once())->method('flush');

        Handler::register($this->client)->shutdownHandler();
    }

    public function testCanFatalShutdown()
    {
        $error = $this->getFunctionMock('Bugsnag', 'error_get_last');
        $error->expects($this->once())->will($this->returnValue(['type' => E_ERROR, 'message' => 'Undefined variable: a', 'file' => '/foo/index.php', 'line' => 2]));

        $this->client->expects($this->once())->method('notify');
        $this->client->expects($this->once())->method('flush');

        Handler::register($this->client)->shutdownHandler();
    }
}
{'fraction_non_alphanumeric': 0.16952129995608256, 'fraction_numerical': 0.006148440931049627, 'mean_word_length': 3.367209971236817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 114, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3586931', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1267, 'n_words': 189}