Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 175 forks source link

Support calling objective-c methods and closures with nil #374

Open dekpient opened 3 years ago

dekpient commented 3 years ago

Hello, I'm trying to fix 2 issues I found when trying to use Cuckoo/OCMock in a project. I'm currently unable to cover a few code branches because of them.

  1. Calling mock.say(nil) currently fails with -[_NSArrayM insertObject:atIndex:]: object cannot be nil (NSInvalidArgumentException) because NSInvocation+OCMockWrapper doesn't do a null check.
  2. Using objectiveArgumentClosure and calling the closure with nil fails with -[NSNull count]: unrecognized selector sent to instance 0x7fff8002ebb0 (NSInvalidArgumentException). I think it's cause TrustMe doesn't support nullable types. I propose objectiveOptionalArgumentClosure (or maybe objcArgumentClosureWithOptional ?). I can add more of them to support closures with more args if you think this is alright.

I also removed the reference to ObjectiveExamplesTest.swift. It doesn't exist in the project so it's making the build fail.

Cheers

MatyasKriz commented 3 years ago

Hey, @dekpient. Thanks for the PR and thanks for using the OCMock integration!

It's a nice find with the nil, I'll take a look at the code and see what we can do with the second problem you're proposing a solution to.