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 8081525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:45:18+00:00 2026-06-05T16:45:18+00:00

While refactoring my code base I found a piece of code which I’d like

  • 0

While refactoring my code base I found a piece of code which I’d like to extract into a separate class.

It will serve thumbnails for user profile pictures. The class (let’s name it UserImageManager) will hold an instance of UserMapper and an instance of ImageRenderer.

Now I do have a method for retrieving the cached url for a users profile picture. This method retrieves a User object from the UserMapper and triggers the render method of ImageRenderer with the image path stored in the User object.

I wrote a test for this tiny function, mocking out the ImageRenderer and now I do not have a single assertion in this test case. It would not make any sense to assert the return value of the function, because it returns the cache file path, which is returned by the mocked ImageRenderer.

Now my question is: is it still a valid unit test, even with no assertions? Or how should I rewrite my test, not only checking calls to mock objects?

// The unit test
public function renderImageWillReturnCacheImagePath() {
  $this->_userImageManager->setImage(
    // Returns the ImageRenderer mock
    $this->_getImageMock(BASE_PATH . 'uploads/2012-06-06-wegmeister-91792.png', false, false)
  );

  // Invokes the function
  $image = $this->_userImageManager->render('wegmeister');
}

// The method to be tested
public function render($username, $width = false, $height = false) {
  $user = $this->_userMapper->getUserByUsername($username);

  if($user !== false && trim($user->getImage()) !== '') {
    $srcImage = $this->_folderUserImages . $user->getImage();
  }
  else {
    $srcImage = $this->_placeholderUserImage;
  }

  $dstImage = $this->_image->render($srcImage, 'jpg', $width, $height);
  if ($dstImage === false || empty($dstImage)) {
    throw new UnexpectedValueException('ImageRenderingFailed');
  }

  return $dstImage;
}
  • 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-05T16:45:19+00:00Added an answer on June 5, 2026 at 4:45 pm

    A test with no assertion is an incomplete test.

    If you can’t imagine what and how to assert, I’d say it means that the outcome of the method (unit) you want to test is undefined.

    As you have not shown any specification nor told which type that function returns, the only thing I could imagine that you can test is if the exeception is thrown when needed.

    Additionally it looks like that that method does too much and is too complex. So I would invest the time not in creating tests but to refactor the classes.

    In the future you should write tests before you write the code, so you don’t come into this situation.

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

Sidebar

Related Questions

I got a code review remark today to extract this anonymous class into a
While doing some refactoring I've found that I'm quite often using a pair or
While ruby does allow modifying any class at any place in the code, I
I unfortunately was doing a little code archeology today (while refactoring out some old
While refactoring some code, I came across this strange compile error: The constructor call
Recently I have been refactoring some of my C# code and I found a
I am in a project where we are starting refactoring some massive code base.
While refactoring code and ridding myself of all those #defines that we're now taught
While refactoring some old code I have stripped out a number of public methods
I have been looking into refactoring some old code into a new WCF service,

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.