Git Product home page Git Product logo

Comments (4)

tspindler-cms avatar tspindler-cms commented on September 20, 2024

Hi,

I'm interested in getting JSON output for your classes to store the results in MongoDB. I went ahead and experimented with the code base, knowing not much of PHP:

use JsonSerializable;
class Vehicle implements JsonSerializable {

     * Get the json representation of the object
     *
     * @return  string
     */
    public function jsonSerialize() {
        return [
            'name' => $this->getName(),
            'type' => $this->getType(),
            'class' => $this->getClass(),
            'number' => $this->getNumber(),
            'ballast' => $this->getBallast(),
            'restrictor' => $this->getRestrictor(),
            'skin' => $this->getSkin(),
            'friendlyName' => $this->getFriendlyName()
        ];
    }

As you're far more knowledgable on PHP than I ever will be, do you think this is a sound approach? If so, I'll continue and push it to github.

from simresults.

mauserrifle avatar mauserrifle commented on September 20, 2024

Yes I think this would be the approach :) Anyway create it what works for you. Eventually when I have time one day, I might use it. Thanks for wanting to share with others!

from simresults.

tspindler-cms avatar tspindler-cms commented on September 20, 2024

Hi, thanks for the encouraging words. I cloned your repo and added JSON serialize functions to most classes: https://github.com/tspindler-cms/simresults I'm not sure on how to proceed on testing these, would you happen to have some ideas for that?

from simresults.

mauserrifle avatar mauserrifle commented on September 20, 2024

Cool! 👍 Take a look at the specs folder. You could add a function called called it_can_cast_to_json to a specific class test file. Set some test values and then check the json output.

For example see it_can_cast_to_string on LapSpec. Very similar:
https://github.com/mauserrifle/simresults/blob/develop/spec/Simresults/LapSpec.php#L23

You can run the spec tests using ./vendor/bin/phpspec run

from simresults.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.