Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4024080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:40:38+00:00 2026-05-20T10:40:38+00:00

phpunit test: public function testSizeOver64K() { try { $this->login(); $scriptname = ‘test script4’; $this->fixture->installScript($scriptname,

  • 0

phpunit test:

public function testSizeOver64K() {
        try {
            $this->login();
            $scriptname = 'test script4';
            $this->fixture->installScript($scriptname, $this->scripts[$scriptname]);
        }
        catch (Exception $expected) {
            return;
        }
        $this->fail('An expected exception has not been raised.');

    }

Functions methods it calls

function installScript($scriptname, $script, $makeactive = false)
    {
        $this->cmdPutScript($scriptname, $script);

        if ($makeactive)
            $this->cmdSetActive($scriptname);

        return true;
    }
private function cmdPutScript($scriptname, $scriptdata)
    {
        if (self::STATE_TRANSACTION != $this->state) {
            $msg = 'Not currently in TRANSACTION state';
            $code = 1;
            throw new Exception($msg, $code);
        }

        $stringLength = $this->getLineLength($scriptdata);

        $this->doCmd(sprintf("PUTSCRIPT \"%s\" {%d+}\r\n%s", $scriptname, $stringLength, $scriptdata));

        return true;
    }
private function getLineLength($string) {
        if (extension_loaded('mbstring') || @dl(PHP_SHLIB_PREFIX.'mbstring.'.PHP_SHLIB_SUFFIX)) {
            $lenght = mb_strlen($string,'8bit');
            if ( $lenght > 65536 ) {
                $msg = "Script is over 64K";
                throw new Exception($msg);
            }   
            return $lenght;
        } else {
            $lenght = strlen($string);
            if ( $lenght > 65536 ) {
                $msg = "Script is over 64K";
                throw new Exception($msg);
            }   
            return $lenght;
        }
    }

Can someone give tips why phpunit doesnt catch the exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:40:39+00:00Added an answer on May 20, 2026 at 10:40 am

    Use a debugger and step through the testcase to make sure your code actually throws the Exception in the first place. It’s impossible to tell from your code whether the environment is setup in a way that would result in an Exception.


    On a sidenote, you are supposed to throw less generic exceptions. You are using try/catch so the following is not applicable to your problem at hand, but take note of

    Implemented GH-88: @expectedException (and setExpectedException()) no longer accept Exception as the expected exception class.

    See changelog for PHPUnit 3.6 and https://github.com/sebastianbergmann/phpunit/pull/88

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting to try and test my Doctrine objects with PHPUnit, and would like
I have the following test case: include_once('../Logger.php'); class LoggerTest extends PHPUnit_Framework_TestCase { public function
I'm currently working with PHPUnit to try and develop tests alongside what I'm writing,
I'm just starting to try out phpunit on some existing code. The naming convention
I'm writing some unit test with phpUnit to test a Zend Framework application and
I'm working on a test in phpunit and I'm running into an issue. I
I'm trying to use PHPUnit to unit test some class methods that return SQL.
I'm trying to write a unit test with phpunit for a model that uses
How would you test the following code with phpUnit? class Product { protected $id
How to run PHPUnit test suite with bootstrap file with phing? My app structure:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.