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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:10:21+00:00 2026-05-26T04:10:21+00:00

Can anyone help me with what assertions are required in a basic save method

  • 0

Can anyone help me with what assertions are required in a basic save method test case in CakePHP 2.0?

I have Product, User and News model, I am looking to write a test case for the submit method in the News model and there are so many ways/things to include I was just wondering what is actually needed and what isn’t. I have basic fixtures setup for all models.

The method I’m testing will effectively be this:

class News extends AppModel {
    public submit($productId, $userId, $newsData) { 
        // Logic which checks for user and products existence, saves and returns submitted row
    }
}

Test Case

public function testSubmit() {

    // Save News
    $newsData = array(
        'News' => array(
            'title' => 'Here is the title of the news',
            'body' => 'Here is the news body',
            'source' => 'News came from here'
        )
    );

    $news = $this->News->submit('product-1', 'user-1', $newsData);

    // Now what?
}
  • 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-26T04:10:22+00:00Added an answer on May 26, 2026 at 4:10 am

    Simply assert that $news is an array, object, that the array is equal to an array you expect… Whatever your method returns, you should know it even before implementing the method (test driven development) and be able to assert the result using one or more than one of the phpunit assert methods.

    Like simply $this->assertTrue($news); Check the manual for all the asserts. http://www.phpunit.de/manual/current/en/

    Also look at the CakePHP core tests to get an idea of how to do test.

    Or look at some open source plugin exmaples like
    https://github.com/CakeDC/tags/blob/2.0/Test/Case/Model/TaggedTest.php
    or
    https://github.com/CakeDC/users/blob/2.0/Test/Case/Model/UserTest.php

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

Sidebar

Related Questions

Can anyone help? I have a PHP method that sends an http post: <?php
Can anyone help? I have been designing a site using Javascript but the rest
Can anyone help? I have been using the entity framework and its going well
can anyone help? I have a simple html file which i am filling via
Can anyone help? I have an issue with calling a asp.net webservice from jquery..
can anyone help me to learn how to use XML. As a test i
Can anyone help, I have 2 applications and they are nearly identical. they have
Can anyone help, seem to have an issue placing a onclick event of an
Can anyone help, I have a popup that is being blocked. It is a
can anyone help? I have small procedure to read in an UTF-8 file with

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.