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

  • SEARCH
  • Home
  • 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 9202159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:11:21+00:00 2026-06-17T23:11:21+00:00

I am using namespacing in 5.3 and trying to test for an expected exception

  • 0

I am using namespacing in 5.3 and trying to test for an expected exception in PHPUnit with the Symfony2 framework.

I am expecting an exception to be thrown and when I use the

$this->setExpectedException('ImageResizerException');

I get the following error:

PHPUnit 3.7.13 by Sebastian Bergmann.

Configuration read from
/var/www/branches/3.6.0/api/app/phpunit.xml.dist

.E……………..

Time: 1 second, Memory: 18.25Mb

There was 1 error:

1)
AssetManagerBundle\Tests\Services\ImageResizerTest::testOriginalFile
ReflectionException: Class ImageResizerException does not exist

FAILURES! Tests: 19, Assertions: 54, Errors: 1.

I have the following structure:

  1. AssetManagerBundle\Services\ImageResizer.php
  2. AssetManagerBundle\Services\Exceptions\ImageResizerException.php
  3. AssetManagerBundle\Tests\Services\ImageResizerTest.php

My test class:

<?php
    namespace AssetManagerBundle\Tests\Services;

    use AssetManagerBundle\Services\ImageResizer;
    use AssetManagerBundle\Services\Exceptions\ImageResizerException;

class ImageResizerTest extends \PHPUnit_Framework_TestCase
{

    public function testOriginalFile()
    {
        $ir = new ImageResizer();
        // test default value
        $this->assertEquals('', $ir->getOriginalFile());

        // test invalid filename
        $this->setExpectedException('ImageResizerException');
        $ir->setOriginalFile('/tmp/test.file');
        $this->assertEquals('/tmp/test.file', $ir->getOriginalFile());


        // test valid filename
        $temp_name  = tempnam(sys_get_temp_dir(), 'test_'.time());
        $handle     = fopen($temp_name, 'w+');
        fwrite($handle, ' ');
        fclose($handle);

        $ir->setOriginalFile($temp_name);
        $this->assertEquals($temp_name, $ir->getOriginalFile());
    }
    // more code....
}

Do I have to do something special for PHPUnit to see my exception class?

PHP Version:

PHP 5.3.10-1ubuntu3.5 with Suhosin-Patch (cli) (built: Jan 18 2013
23:45:59) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0,
Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

  • 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-06-17T23:11:22+00:00Added an answer on June 17, 2026 at 11:11 pm

    You need to fully qualify the exception class along with its namespace. For ex:

    $this->setExpectedException('\AssetManagerBundle\Services\Exceptions\ImageResizerException');
    

    or

    use AssetManagerBundle\Services\Exceptions\ImageResizerException;
    $exceptionClass = get_class(new ImageResizerException(''));
    $this->setExpectedException($exceptionClass);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use PDO::FETCH_CLASS on an object. I am using namespacing and
what is the use of using declaration type of namespacing over using directive type
I have been using Ubuntu for a while, and now trying to use OS
I'm trying to implement namespacing using the self-executing anonymous functions in CoffeeScript: How do
I'm trying to create a jQuery Plugin using there name spacing system, so this
I am trying to convert some code from using DOM (via jDOM) to use
I use to enjoy using js. Now I am just frustrated. I am trying
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
I'm trying to use Jenkins' Plot plugin to generate a graph of how many

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.